{"modulePath":"github.com/plexsphere/plexd","version":"v0.43.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package proxytest\n\nPackage proxytest is an HTTP proxy that answers CONNECT and nothing else, so a test can show that a client reaches a server only through a proxy, and how the client takes a proxy that refuses it. The Go tests run it in the test process, and the mock control plane runs it for the e2e suites.\n\nThe package imports neither testing nor internal/api: the mock is a program, and the tests of internal/api import this package.\n\n## Types\n\n```go\ntype Options struct {\n\tTLS      *tls.Config // non-nil: the listener speaks TLS\n\tUsername string      // with Password: the Basic credentials a CONNECT must carry\n\tPassword string\n\tTarget   string // non-empty: the only host:port a CONNECT may name\n\tUpstream string // non-empty: the address every admitted tunnel connects to, in place of the CONNECT target\n}\n```\nOptions says what a Proxy asks of a client and where its tunnels lead. The zero value is a plain proxy that tunnels to any target.\n\n```go\ntype Proxy struct {\n\t// contains filtered or unexported fields\n}\n```\nProxy is a CONNECT proxy. Listen makes one, and it answers once Serve runs.\n\n```go\nfunc Listen(addr string, opts Options) (*Proxy, error)\n```\nListen binds addr, a host:port as net.Listen takes it, and returns the proxy that Serve runs on it. A TLS listener offers no ALPN protocol, whatever opts.TLS names, because the proxy speaks HTTP/1.1 only.\n\n```go\nfunc (p *Proxy) Addr() net.Addr\n```\nAddr returns the address the proxy is bound to, with the port the kernel chose when Listen was given port 0.\n\n```go\nfunc (p *Proxy) Serve(ctx context.Context) error\n```\nServe accepts connections until ctx ends and returns nil then, or the error of a listener that failed before. Either way it has closed the listener and every tunnel, and waited for their goroutines, when it returns.\n\nDECISION: Serve reads the requests itself instead of running an http.Server. A tunnel needs the connection hijacked, and http.Server.Close neither closes a hijacked connection nor waits for its handler.\n\n```go\nfunc (p *Proxy) Stats() Stats\n```\nStats returns the counts so far.\n\n```go\ntype Stats struct {\n\tTunnels       int      `json:\"tunnels\"`        // CONNECTs answered 200\n\tRefusedAuth   int      `json:\"refused_auth\"`   // answered 407\n\tRefusedTarget int      `json:\"refused_target\"` // answered 403\n\tOtherRequests int      `json:\"other_requests\"` // not a CONNECT, answered 405\n\tTargets       []string `json:\"targets\"`        // distinct host:port of admitted CONNECTs, sorted\n}\n```\nStats counts the answers a Proxy gave. A CONNECT whose upstream could not be dialed, answered 502, is counted nowhere. Each answer is counted before it is sent, so a client that has read one finds it here.\n\n","path":"github.com/plexsphere/plexd/internal/proxytest","name":"proxytest","synopsis":"Package proxytest is an HTTP proxy that answers CONNECT and nothing else, so a test can show that a client reaches a server only through a proxy, and how the client takes a proxy that refuses it.","isRedistributable":true}
