utlstransport

package module
v0.0.0-...-9b809d1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: MIT Imports: 16 Imported by: 0

README

utlstransport

This is a proof of concept HTTP transport for using github.com/refraction-networking/utls.

The code in this repository is unmaintained. Use at your own risk.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UHTTPDefaultTransport http.RoundTripper = &UHTTPTransport{}

UHTTPDefaultTransport is the default UHTTPTransport.

Functions

This section is empty.

Types

type UHTTPTransport

type UHTTPTransport struct {

	// DialContext is the optional dialer to dial connections
	// just like the namesake field of http.Transport. If this
	// dialer is set, we'll use it for dialing all conns.
	DialContext func(ctx context.Context, network, address string) (net.Conn, error)

	// Proxy is like the namesake field in http.Transport. If
	// not initialized, or if it returns a nil URL, then there
	// will be no proxying of connections. We support the
	// same types of proxies as the stdlib for HTTP but we
	// only support socks5 proxies for HTTPS/H2.
	Proxy func(*http.Request) (*url.URL, error)

	// TLSClientConfig contains optional UTLS configuration for
	// this transport. We will default-construct a config
	// instance if this field is not set. Otherwise,
	// every dial attempt will use a Clone() of this field.
	TLSClientConfig *utls.Config

	// TLSHandshakeTimeout is the optional maximum timeout we are
	// willing to wait for the TLS handshake. If not set, we'll
	// use a default TLS-handshake timeout of ten seconds.
	TLSHandshakeTimeout time.Duration

	// UTLSClientHelloID is the optional UTLS ClientHelloID
	// that you would like to use with this transport. If
	// nil, we will use utls.HelloFirefox_Auto.
	UTLSClientHelloID *utls.ClientHelloID
	// contains filtered or unexported fields
}

UHTTPTransport uses UTLS instead of TLS. This struct mimicks an http.Transport and matches the http.RoundTripper standard library interface.

As documented in https://github.com/refraction-networking/utls/issues/16, the standard library http.RoundTripper cannot use connections from UTLS because httpTransport enables http2 only when it's possible to cast the net.Conn to a *tls.Conn.

This transport attempts to solve this issue by inspecting the ALPN negotiated protocol and routing:

- "h2" to a default constructed http2.Transport;

- "http/1.1" to a default constructed http.Transport.

Moreover, cleartext HTTP requests go to a default constructed http.Transport.

The zero initialized UHTTPTransport is valid and can be used immediately. We will allocate internal variables when we need them. As http.Transport, UHTTPTransport may have idle connections, for which CloseIdleConnections can be used.

You SHOULD NOT modify the public fields of this data structure while it's being used, because that MAY quite possibly lead to data races. Otherwise, it is safe to call the methods of this struct from several concurrent goroutines.

func (*UHTTPTransport) CloseIdleConnections

func (txp *UHTTPTransport) CloseIdleConnections()

CloseIdleConnections allows an http.Client controlling this transport to close the idle connections.

func (*UHTTPTransport) RoundTrip

func (txp *UHTTPTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.RoundTrip.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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