memhttp

package
v0.4.28 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: BSD-3-Clause-Clear Imports: 11 Imported by: 0

Documentation

Overview

Package memhttp provides an in-memory HTTP server and client. For testing-specific adapters, see the memhttptest subpackage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option configures a Server.

func WithCleanupTimeout

func WithCleanupTimeout(d time.Duration) Option

WithCleanupTimeout customizes the default five-second timeout for the server's Cleanup method. It's most useful with the memhttptest subpackage.

func WithErrorLog

func WithErrorLog(l *log.Logger) Option

WithErrorLog sets http.Server.ErrorLog.

func WithOptions

func WithOptions(opts ...Option) Option

WithOptions composes multiple Options into one.

type Server

type Server struct {
	Listener *memoryListener
	// contains filtered or unexported fields
}

Server is a net/http server that uses in-memory pipes instead of TCP. By default, it has TLS enabled and supports HTTP/2. It otherwise uses the same configuration as the zero value of http.Server.

func New

func New(handler http.Handler, opts ...Option) *Server

New constructs and starts a Server.

func (*Server) Cleanup

func (s *Server) Cleanup() error

Cleanup calls Shutdown with a five second timeout. To customize the timeout, use WithCleanupTimeout.

Cleanup is primarily intended for use in tests. If you find yourself using it, you may want to use the memhttptest package instead.

func (*Server) Client

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

Client returns an http.Client configured to use in-memory pipes rather than TCP, disable automatic compression, trust the server's TLS certificate (if any), and use HTTP/2 (if the server supports it).

Callers may reconfigure the returned client without affecting other clients.

func (*Server) Close

func (s *Server) Close() error

Close immediately shuts down the server. To shut down the server without interrupting in-flight requests, use Shutdown.

func (*Server) RegisterOnShutdown

func (s *Server) RegisterOnShutdown(f func())

RegisterOnShutdown registers a function to call on Shutdown. It's often used to cleanly shut down connections that have been hijacked. See http.Server.RegisterOnShutdown for details.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server, without interrupting any active connections. See http.Server.Shutdown for details.

func (*Server) Transport

func (s *Server) Transport() *http2.Transport

Transport returns an http2.Transport configured to use in-memory pipes rather than TCP, disable automatic compression, trust the server's TLS certificate (if any), and use HTTP/2 (if the server supports it).

Callers may reconfigure the returned Transport without affecting other transports or clients.

func (*Server) URL

func (s *Server) URL() string

URL returns the server's URL.

Jump to

Keyboard shortcuts

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