Documentation
¶
Overview ¶
This package provides an interface to functions and structs in the standard net/http package used for servers to facilitate mocking.
Index ¶
- Constants
- Variables
- type ConnState
- type Cookie
- type CookieJar
- type Dir
- type File
- type FileSystem
- type Flusher
- type HTTP
- type HTTP2Config
- type Handler
- type HandlerFunc
- type Header
- type Hijacker
- type MaxBytesError
- type Protocols
- type PushOptions
- type Pusher
- type Request
- type ResponseWriter
- type RoundTripper
- type SameSite
- type Server
- type ServerOption
- func WithAddr(addr string) ServerOption
- func WithBaseContext(f func(net.Listener) context.Context) ServerOption
- func WithConnContext(f func(context.Context, net.Conn) context.Context) ServerOption
- func WithConnState(f func(net.Conn, ConnState)) ServerOption
- func WithDisableGeneralOptionsHandler(v bool) ServerOption
- func WithErrorLog(l *log.Logger) ServerOption
- func WithHTTP2(cfg *HTTP2Config) ServerOption
- func WithHandler(handler Handler) ServerOption
- func WithIdleTimeout(t time.Duration) ServerOption
- func WithMaxHeaderBytes(n int) ServerOption
- func WithProtocols(p *Protocols) ServerOption
- func WithReadHeaderTimeout(t time.Duration) ServerOption
- func WithReadTimeout(t time.Duration) ServerOption
- func WithTLSConfig(cfg *tls.Config) ServerOption
- func WithTLSNextProto(m map[string]func(*http.Server, *tls.Conn, http.Handler)) ServerOption
- func WithWriteTimeout(t time.Duration) ServerOption
Constants ¶
const ( MethodGet = http.MethodGet MethodHead = http.MethodHead MethodPost = http.MethodPost MethodPut = http.MethodPut MethodPatch = http.MethodPatch MethodDelete = http.MethodDelete MethodConnect = http.MethodConnect MethodOptions = http.MethodOptions MethodTrace = http.MethodTrace )
const ( StatusContinue = http.StatusContinue StatusSwitchingProtocols = http.StatusSwitchingProtocols StatusProcessing = http.StatusProcessing StatusEarlyHints = http.StatusEarlyHints StatusOK = http.StatusOK StatusCreated = http.StatusCreated StatusAccepted = http.StatusAccepted StatusNonAuthoritativeInfo = http.StatusNonAuthoritativeInfo StatusNoContent = http.StatusNoContent StatusResetContent = http.StatusResetContent StatusPartialContent = http.StatusPartialContent StatusMultiStatus = http.StatusMultiStatus StatusAlreadyReported = http.StatusAlreadyReported StatusIMUsed = http.StatusIMUsed StatusMultipleChoices = http.StatusMultipleChoices StatusMovedPermanently = http.StatusMovedPermanently StatusFound = http.StatusFound StatusSeeOther = http.StatusSeeOther StatusNotModified = http.StatusNotModified StatusUseProxy = http.StatusUseProxy StatusTemporaryRedirect = http.StatusTemporaryRedirect StatusPermanentRedirect = http.StatusPermanentRedirect StatusBadRequest = http.StatusBadRequest StatusPaymentRequired = http.StatusPaymentRequired StatusForbidden = http.StatusForbidden StatusNotFound = http.StatusNotFound StatusMethodNotAllowed = http.StatusMethodNotAllowed StatusNotAcceptable = http.StatusNotAcceptable StatusProxyAuthRequired = http.StatusProxyAuthRequired StatusRequestTimeout = http.StatusRequestTimeout StatusConflict = http.StatusConflict StatusGone = http.StatusGone StatusLengthRequired = http.StatusLengthRequired StatusPreconditionFailed = http.StatusPreconditionFailed StatusRequestEntityTooLarge = http.StatusRequestEntityTooLarge StatusRequestURITooLong = http.StatusRequestURITooLong StatusUnsupportedMediaType = http.StatusUnsupportedMediaType StatusRequestedRangeNotSatisfiable = http.StatusRequestedRangeNotSatisfiable StatusExpectationFailed = http.StatusExpectationFailed StatusTeapot = http.StatusTeapot StatusMisdirectedRequest = http.StatusMisdirectedRequest StatusUnprocessableEntity = http.StatusUnprocessableEntity StatusLocked = http.StatusLocked StatusFailedDependency = http.StatusFailedDependency StatusTooEarly = http.StatusTooEarly StatusUpgradeRequired = http.StatusUpgradeRequired StatusPreconditionRequired = http.StatusPreconditionRequired StatusTooManyRequests = http.StatusTooManyRequests StatusRequestHeaderFieldsTooLarge = http.StatusRequestHeaderFieldsTooLarge StatusInternalServerError = http.StatusInternalServerError StatusNotImplemented = http.StatusNotImplemented StatusBadGateway = http.StatusBadGateway StatusGatewayTimeout = http.StatusGatewayTimeout StatusHTTPVersionNotSupported = http.StatusHTTPVersionNotSupported StatusVariantAlsoNegotiates = http.StatusVariantAlsoNegotiates StatusInsufficientStorage = http.StatusInsufficientStorage StatusLoopDetected = http.StatusLoopDetected StatusNotExtended = http.StatusNotExtended StatusNetworkAuthenticationRequired = http.StatusNetworkAuthenticationRequired )
const ( DefaultMaxHeaderBytes = http.DefaultMaxHeaderBytes DefaultMaxIdleConnsPerHost = http.DefaultMaxIdleConnsPerHost TimeFormat = http.TimeFormat TrailerPrefix = http.TrailerPrefix )
Variables ¶
var ( ErrNotSupported = http.ErrNotSupported ErrUnexpectedTrailer = http.ErrUnexpectedTrailer // Deprecated ErrMissingBoundary = http.ErrMissingBoundary ErrNotMultipart = http.ErrNotMultipart ErrHeaderTooLong = http.ErrHeaderTooLong // Deprecated ErrShortBody = http.ErrShortBody // Deprecated ErrMissingContentLength = http.ErrMissingContentLength // Deprecated ErrBodyNotAllowed = http.ErrBodyNotAllowed ErrHijacked = http.ErrHijacked ErrContentLength = http.ErrContentLength ErrWriteAfterFlush = http.ErrWriteAfterFlush // Deprecated ServerContextKey = http.ServerContextKey LocalAddrContextKey = http.LocalAddrContextKey DefaultClient = http.DefaultClient DefaultServeMux = http.DefaultServeMux ErrAbortHandler = http.ErrAbortHandler ErrBodyReadAfterClose = http.ErrBodyReadAfterClose ErrHandlerTimeout = http.ErrHandlerTimeout ErrLineTooLong = http.ErrLineTooLong ErrMissingFile = http.ErrMissingFile ErrNoCookie = http.ErrNoCookie ErrNoLocation = http.ErrNoLocation ErrSchemeMismatch = http.ErrSchemeMismatch ErrServerClosed = http.ErrServerClosed ErrSkipAltProtocol = http.ErrSkipAltProtocol ErrUseLastResponse = http.ErrUseLastResponse NoBody = http.NoBody )
Functions ¶
This section is empty.
Types ¶
type FileSystem ¶
type FileSystem = http.FileSystem
type HTTP ¶
type HTTP interface {
CanonicalHeaderKey(string) string
DetectContentType([]byte) string
Error(ResponseWriter, string, int)
Handle(string, http.Handler)
HandleFunc(string, func(ResponseWriter, *http.Request))
ListenAndServe(string, http.Handler) error
ListenAndServeTLS(string, string, string, http.Handler) error
MaxBytesReader(ResponseWriter, io.ReadCloser, int64) io.ReadCloser
NotFound(ResponseWriter, *http.Request)
ParseHTTPVersion(string) (int, int, bool)
ParseTime(string) (time.Time, error)
ProxyFromEnvironment(*http.Request) (*url.URL, error)
ProxyURL(*url.URL) func(*http.Request) (*url.URL, error)
Redirect(ResponseWriter, *http.Request, string, int)
Serve(net.Listener, http.Handler) error
ServeContent(ResponseWriter, *http.Request, string, time.Time, io.ReadSeeker)
ServeFile(ResponseWriter, *http.Request, string)
ServeFileFS(ResponseWriter, *http.Request, fs.FS, string)
ServeTLS(net.Listener, http.Handler, string, string) error
SetCookie(ResponseWriter, *Cookie)
StatusText(int) string
}
HTTP is an interface for the functions in the net/http package when used in a server
type HTTP2Config ¶ added in v0.0.6
type HTTP2Config = http.HTTP2Config
type HandlerFunc ¶
type HandlerFunc = http.HandlerFunc
type MaxBytesError ¶
type MaxBytesError = http.MaxBytesError
type PushOptions ¶
type PushOptions = http.PushOptions
type Request ¶
type Request interface {
Method() string
URL() *url.URL
Proto() string
ProtoMajor() int
ProtoMinor() int
Header() Header
Body() io.ReadCloser
GetBody() func() (io.ReadCloser, error)
ContentLength() int64
TransferEncoding() []string
Host() string
Form() url.Values
PostForm() url.Values
MultipartForm() *multipart.Form
Trailer() Header
RemoteAddr() string
RequestURI() string
TLS() *tls.ConnectionState
Pattern() string
}
Request provides an interface to a net/http.Request for use on a server receiving an http request.
type ResponseWriter ¶
type ResponseWriter = http.ResponseWriter
type RoundTripper ¶
type RoundTripper = http.RoundTripper
type Server ¶
type Server interface {
Close() error
ListenAndServe() error
ListenAndServeTLS(string, string) error
RegisterOnShutdown(func())
Serve(net.Listener) error
ServeTLS(net.Listener, string, string) error
SetKeepAlivesEnabled(bool)
Shutdown(context.Context) error
}
Server is an interface for the net/http.Server struct
func NewServer ¶
func NewServer(options ...ServerOption) Server
NewServer creates a Server with default values
type ServerOption ¶
ServerOption allows you to set options on a server in the NewServer constructor
func WithBaseContext ¶
func WithBaseContext(f func(net.Listener) context.Context) ServerOption
Set the net/http.Server BaseContext
func WithConnContext ¶
Set the net/http.Server ConnContext
func WithConnState ¶
func WithConnState(f func(net.Conn, ConnState)) ServerOption
Set the net/http.Server ConnState Note that the function will be called with the underlying connection, not an interface.
func WithDisableGeneralOptionsHandler ¶
func WithDisableGeneralOptionsHandler(v bool) ServerOption
Set the net/http.Server DisableGeneralOptionsHandler
func WithHTTP2 ¶ added in v0.0.6
func WithHTTP2(cfg *HTTP2Config) ServerOption
Set the net/http.Server HTTP2
func WithIdleTimeout ¶
func WithIdleTimeout(t time.Duration) ServerOption
Set the net/http.Server IdleTimeout
func WithMaxHeaderBytes ¶
func WithMaxHeaderBytes(n int) ServerOption
Set the net/http.Server MaxHeaderBytes
func WithProtocols ¶ added in v0.0.6
func WithProtocols(p *Protocols) ServerOption
Set the net/http.Server Protocols
func WithReadHeaderTimeout ¶
func WithReadHeaderTimeout(t time.Duration) ServerOption
Set the net/http.Server ReadHeaderTimeout
func WithReadTimeout ¶
func WithReadTimeout(t time.Duration) ServerOption
Set the net/http.Server ReadTimeout
func WithTLSConfig ¶
func WithTLSConfig(cfg *tls.Config) ServerOption
Set the net/http.Server TLSConfig
func WithTLSNextProto ¶
Set the net/http.Server TLSNextProto TODO: Explore the possibility of replacing the function parameters with interfaces
func WithWriteTimeout ¶
func WithWriteTimeout(t time.Duration) ServerOption
Set the net/http.Server WriteTimeout