Documentation
¶
Overview ¶
This package provides an interface to functions and structs in the standard net/http package when using it as an http client to facilitate mocking.
Index ¶
- Constants
- Variables
- type CheckRedirectFn
- type Client
- type ClientOption
- type ConnState
- type Cookie
- type CookieJar
- type HTTP
- type HTTP2Config
- type Header
- type Protocols
- type Request
- type RequestOption
- func WithBody(r io.ReadCloser) RequestOption
- func WithClose(v bool) RequestOption
- func WithContentLength(l int64) RequestOption
- func WithForm(form url.Values) RequestOption
- func WithGetBody(f func() (io.ReadCloser, error)) RequestOption
- func WithHeader(name string, values ...string) RequestOption
- func WithHeaders(headers Header) RequestOption
- func WithHost(host string) RequestOption
- func WithMultipartForm(form *multipart.Form) RequestOption
- func WithPostForm(form url.Values) RequestOption
- func WithRemoteAddr(addr string) RequestOption
- func WithRequestURI(uri string) RequestOption
- func WithTrailer(t Header) RequestOption
- func WithTransferEncoding(encodings []string) RequestOption
- type Response
- type RoundTripper
- type SameSite
- type Transport
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 )
var WithJar = WithCookieJar
WithJar is just an alias to WithCookieJar
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
CloseIdleConnections()
Do(Request) (Response, error)
Get(string) (Response, error)
Head(string) (Response, error)
Post(string, string, io.Reader) (Response, error)
PostForm(string, url.Values) (Response, error)
GetTransport() RoundTripper
}
Client is an interface for the net/http.Client struct
func WrapClient ¶ added in v0.2.10
type ClientOption ¶
ClientOption allows you to set options on a client in the NewClient constructor
func WithCheckRedirect ¶
Set the net/http.Client CheckRedirect
func WithTransport ¶
func WithTransport(t RoundTripper) ClientOption
Set the net/http.Client Transport
type HTTP ¶
type HTTP interface {
// Client constructors:
NewClient(options ...ClientOption) Client
// Request constructors:
NewRequest(method, url string, body io.Reader, options ...RequestOption) (Request, error)
NewRequestWithContext(ctx context.Context, method, url string, body io.Reader, options ...RequestOption) (Request, error)
// Response constructors:
Get(string) (Response, error)
Head(string) (Response, error)
Post(string, string, io.Reader) (Response, error)
PostForm(string, url.Values) (Response, error)
ReadResponse(*bufio.Reader, *http.Request) (Response, error)
CanonicalHeaderKey(string) string
StatusText(int) string
}
HTTP is an interface for the functions in the net/http package
type HTTP2Config ¶ added in v0.0.6
type HTTP2Config = http.HTTP2Config
type Request ¶
type Request interface {
Write(io.Writer) error
WriteProxy(io.Writer) error
RealRequest() *http.Request
}
Request provides an interface to a net/http.Request for use on a client making an http request.
type RequestOption ¶
RequestOption allows you to set options on a request in the NewRequest constructor
func WithContentLength ¶
func WithContentLength(l int64) RequestOption
Set the net/http.Request ContentLength
func WithGetBody ¶
func WithGetBody(f func() (io.ReadCloser, error)) RequestOption
Set the net/http.Request GetBody
func WithHeader ¶
func WithHeader(name string, values ...string) RequestOption
Set a an individual net/http.Request Header
func WithHeaders ¶
func WithHeaders(headers Header) RequestOption
Set the net/http.Request Header map
func WithMultipartForm ¶
func WithMultipartForm(form *multipart.Form) RequestOption
Set the net/http.Request MultipartForm
func WithPostForm ¶
func WithPostForm(form url.Values) RequestOption
Set the net/http.Request PostForm
func WithRemoteAddr ¶
func WithRemoteAddr(addr string) RequestOption
Set the net/http.RequestForm RemoteAddr
func WithRequestURI ¶
func WithRequestURI(uri string) RequestOption
Set the net/http.RequestForm RequestURI
func WithTransferEncoding ¶
func WithTransferEncoding(encodings []string) RequestOption
Set the net/http.Request TransferEncoding
type Response ¶
type Response interface {
// Simple pass-through methods:
Cookies() []*Cookie
Location() (*url.URL, error)
ProtoAtLeast(int, int) bool
Write(io.Writer) error
// Methods allowing access to member variables:
Status() string
StatusCode() int
Proto() string
ProtoMajor() int
ProtoMinor() int
Header() Header
Body() io.ReadCloser
ContentLength() int64
TransferEncoding() []string
Close() bool
Uncompressed() bool
Trailer() Header
Request() Request
TLS() *tls.ConnectionState
}
Response is an interface to a Response received by the client.
type RoundTripper ¶
type RoundTripper = http.RoundTripper