Documentation
¶
Overview ¶
Package tunnel provides a specialized version of net.Dial that can establish a tunnelled TCP connection via an HTTP proxy that supports the CONNECT method per RFC 2817.
Index ¶
Examples ¶
Constants ¶
View Source
const (
ProxyDeadlineDuration = 30 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
func DialViaProxy ¶
DialViaProxy will establish a TCP connection tunnelled over an HTTP proxy located at the given url. The HTTP proxy must support unauthenticated CONNECT method tunnelling per RFC 2817. The farendAddress must be a host:port of the far-end TCP endpoint. The url must have a scheme of either http or https and explicitly specify the port.
Example ¶
pretendProxy := httptest.NewServer(&ExampleHandler{})
defer pretendProxy.Close()
proxyUrl, err := url.Parse(pretendProxy.URL)
if err != nil {
log.Fatal(err)
}
// Dial a TCP connection to the host at "farend" on port 5000 via the HTTP proxy
conn, err := tunnel.DialViaProxy(proxyUrl, "farend:5000")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
if conn != nil {
fmt.Println("Connection ready to use")
}
// ...proceed with net.Conn operations
// however, this particular conn won't actually work since the built-in HTTP server is not CONNECT aware
Output: Connection ready to use
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.