httptransport

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package httptransport contains HTTP transport extensions. Here we define a http.Transport that emits events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSystemTransport

func NewSystemTransport(dialer Dialer, tlsDialer TLSDialer, proxy ProxyFunc) *http.Transport

NewSystemTransport creates a new "system" HTTP transport. That is a transport using the Go standard library with custom dialer and TLS dialer.

Types

type ByteCountingTransport

type ByteCountingTransport struct {
	RoundTripper
	Counter *bytecounter.Counter
}

ByteCountingTransport is a RoundTripper that counts bytes.

func (ByteCountingTransport) RoundTrip

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

RoundTrip implements RoundTripper.RoundTrip

type Config

type Config struct {
	ByteCounter *bytecounter.Counter // default: no byte counting
	Dialer      Dialer               // default: dialer.DNSDialer
	Logger      Logger               // default: no logging
	Proxy       ProxyFunc            // default: no proxy
	Resolver    Resolver             // default: system resolver
	TLSConfig   *tls.Config          // default: attempt using h2
	TLSDialer   TLSDialer            // default: dialer.TLSDialer
}

Config contains configuration for creating a new transport. When any field of Config is nil/empty, we will use a suitable default.

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

Dialer is the definition of dialer assumed by this package.

type Logger

type Logger interface {
	Debugf(format string, v ...interface{})
	Debug(message string)
}

Logger is the logger assumed by this package

type LoggingTransport

type LoggingTransport struct {
	RoundTripper
	Logger Logger
}

LoggingTransport is a logging transport

func (LoggingTransport) RoundTrip

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

RoundTrip implements RoundTripper.RoundTrip

type ProxyFunc

type ProxyFunc func(*http.Request) (*url.URL, error)

ProxyFunc is the function used to set a proxy.

type Resolver

type Resolver interface {
	LookupHost(ctx context.Context, hostname string) (addrs []string, err error)
}

Resolver is the interface we expect from a resolver

type RoundTripper

type RoundTripper interface {
	RoundTrip(req *http.Request) (*http.Response, error)
	CloseIdleConnections()
}

RoundTripper is the definition of http.RoundTripper used by this package.

func New

func New(config Config) RoundTripper

New creates a new RoundTripper. You can further extend the returned RoundTripper before wrapping it into an http.Client.

type TLSDialer

type TLSDialer interface {
	DialTLSContext(ctx context.Context, network, address string) (net.Conn, error)
}

TLSDialer is the definition of a TLS dialer assumed by this package.

type UserAgentTransport

type UserAgentTransport struct {
	RoundTripper
}

UserAgentTransport is a transport that ensures that we always set an OONI specific default User-Agent header.

func (UserAgentTransport) RoundTrip

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

RoundTrip implements RoundTripper.RoundTrip

Jump to

Keyboard shortcuts

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