http

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
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
)
View Source
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
	StatusUnauthorized                 = http.StatusUnauthorized
	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
	StatusUnavailableForLegalReasons   = http.StatusUnavailableForLegalReasons

	StatusInternalServerError           = http.StatusInternalServerError
	StatusNotImplemented                = http.StatusNotImplemented
	StatusBadGateway                    = http.StatusBadGateway
	StatusServiceUnavailable            = http.StatusServiceUnavailable
	StatusGatewayTimeout                = http.StatusGatewayTimeout
	StatusHTTPVersionNotSupported       = http.StatusHTTPVersionNotSupported
	StatusVariantAlsoNegotiates         = http.StatusVariantAlsoNegotiates
	StatusInsufficientStorage           = http.StatusInsufficientStorage
	StatusLoopDetected                  = http.StatusLoopDetected
	StatusNotExtended                   = http.StatusNotExtended
	StatusNetworkAuthenticationRequired = http.StatusNetworkAuthenticationRequired
)
View Source
const (
	DefaultMaxHeaderBytes      = http.DefaultMaxHeaderBytes
	DefaultMaxIdleConnsPerHost = http.DefaultMaxIdleConnsPerHost
	TimeFormat                 = http.TimeFormat
	TrailerPrefix              = http.TrailerPrefix
)

Variables

View Source
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 ConnState

type ConnState = http.ConnState
type Cookie = http.Cookie

type CookieJar

type CookieJar = http.CookieJar

type Dir

type Dir = http.Dir

type File

type File = http.File

type FileSystem

type FileSystem = http.FileSystem

type Flusher

type Flusher = http.Flusher

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

func NewHTTP

func NewHTTP() HTTP

NewHTTP creates a new HTTP instance.

type HTTP2Config added in v0.0.6

type HTTP2Config = http.HTTP2Config

type Handler

type Handler = http.Handler

type HandlerFunc

type HandlerFunc = http.HandlerFunc
type Header = http.Header

type Hijacker

type Hijacker = http.Hijacker

type MaxBytesError

type MaxBytesError = http.MaxBytesError

type Protocols added in v0.0.6

type Protocols = http.Protocols

type PushOptions

type PushOptions = http.PushOptions

type Pusher

type Pusher = http.Pusher

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 SameSite

type SameSite = http.SameSite

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

func WrapServer added in v0.2.9

func WrapServer(svr *http.Server) Server

type ServerOption

type ServerOption func(svr *http.Server)

ServerOption allows you to set options on a server in the NewServer constructor

func WithAddr

func WithAddr(addr string) ServerOption

Set the net/http.Server Addr

func WithBaseContext

func WithBaseContext(f func(net.Listener) context.Context) ServerOption

Set the net/http.Server BaseContext

func WithConnContext

func WithConnContext(f func(context.Context, net.Conn) context.Context) ServerOption

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 WithErrorLog

func WithErrorLog(l *log.Logger) ServerOption

Set the net/http.Server ErrorLog

func WithHTTP2 added in v0.0.6

func WithHTTP2(cfg *HTTP2Config) ServerOption

Set the net/http.Server HTTP2

func WithHandler

func WithHandler(handler Handler) ServerOption

Set the net/http.Server Handler

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

func WithTLSNextProto(m map[string]func(*http.Server, *tls.Conn, http.Handler)) ServerOption

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

Jump to

Keyboard shortcuts

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