httpstest

package
v0.0.0-...-fe628ba Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: AGPL-3.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InsecureSink

func InsecureSink(sinkAddr string) *http.Transport

InsecureSink returns a transport that always dials to the specified address, and skips certificate verification.

func SinkDialFunc

func SinkDialFunc(sinkAddr string) func(
	ctx context.Context, net, addr string,
) (net.Conn, error)

SinkDialFunc returns a dialing function that always dials to the same address.

Types

type DualServer

type DualServer struct {
	HTTP       *httptest.Server
	HTTPS      *httptest.Server
	TLSConfigs *TLSConfigs
	Transport  *http.Transport
}

DualServer wraps two *httptest.Server's with a transport that goes to one of them base on HTTP or HTTPS.

func NewDualServer

func NewDualServer(domains []string, h http.Handler) (*DualServer, error)

NewDualServer creates an HTTPS dual server for the given testing domains.

func (*DualServer) Client

func (s *DualServer) Client() *http.Client

Client creates an HTTP client which transport connects directly to one of the servers base on the protocol port.

type Server

type Server struct {
	*httptest.Server

	TLSConfigs *TLSConfigs
	Transport  *http.Transport
}

Server wraps a *httptest.Server with HTTP support.

func NewServer

func NewServer(domains []string, h http.Handler) (*Server, error)

NewServer creates an HTTPS server for the given testing domains.

func (*Server) Client

func (s *Server) Client() *http.Client

Client creates an HTTP client which transport connects directly to the server.

func (*Server) SinkTransport

func (s *Server) SinkTransport(tr *http.Transport)

SinkTransport sinks the transport to the server and sets the TLS client config.

type TLSConfigs

type TLSConfigs struct {
	Domains []string
	Server  *tls.Config
	Client  *tls.Config
}

TLSConfigs creates the certificate setup required for a set of domains.

func NewTLSConfigs

func NewTLSConfigs(domains []string) (*TLSConfigs, error)

NewTLSConfigs creates a new setup with proper TLS config and HTTP

func (*TLSConfigs) Sink

func (c *TLSConfigs) Sink(sinkAddr string) *http.Transport

Sink returns a transport where every outgoing connection dials the same sinkAddr but assumes the address is certified as the domains in the TLSConfigs.

func (*TLSConfigs) SinkHTTPS

func (c *TLSConfigs) SinkHTTPS(httpAddr, httpsAddr string) *http.Transport

SinkHTTPS returns a transport where outgoing https connections dial httpsAddr and all other outgoing connections dial httpAddr. When it is HTTPS, it assumes the address is certified as the domains in TLSConfigs.

Jump to

Keyboard shortcuts

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