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 ¶
WithCleanupTimeout customizes the default five-second timeout for the server's Cleanup method. It's most useful with the memhttptest subpackage.
func WithOptions ¶
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 (*Server) Cleanup ¶
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 ¶
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 ¶
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 ¶
Shutdown gracefully shuts down the server, without interrupting any active connections. See http.Server.Shutdown for details.
func (*Server) 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.