tunnel

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2019 License: Apache-2.0 Imports: 10 Imported by: 1

README

Go Documentation CircleCI

Example

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

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

func DialViaProxy(url *url.URL, farendAddress string) (net.Conn, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL