{"modulePath":"github.com/theopenlane/httpsling","version":"v0.3.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpsling\n\nPackage httpsling is a wrapper for creating and sending http httpsling (e.g. for webhooks, external 3d party integrations)\n\n## Constants\n\n```go\nconst (\n\t// Authentication\n\tHeaderAuthorization      = \"Authorization\"\n\tHeaderProxyAuthenticate  = \"Proxy-Authenticate\"\n\tHeaderProxyAuthorization = \"Proxy-Authorization\"\n\tHeaderWWWAuthenticate    = \"WWW-Authenticate\"\n\n\tBearerAuthHeader = \"Bearer \"\n\tBasicAuthHeader  = \"Basic \"\n\n\t// Caching\n\tHeaderAge           = \"Age\"\n\tHeaderCacheControl  = \"Cache-Control\"\n\tHeaderClearSiteData = \"Clear-Site-Data\"\n\tHeaderExpires       = \"Expires\"\n\tHeaderPragma        = \"Pragma\"\n\tHeaderWarning       = \"Warning\"\n\n\t// Client hints\n\tHeaderAcceptCH         = \"Accept-CH\"\n\tHeaderAcceptCHLifetime = \"Accept-CH-Lifetime\"\n\tHeaderContentDPR       = \"Content-DPR\"\n\tHeaderDPR              = \"DPR\"\n\tHeaderEarlyData        = \"Early-Data\"\n\tHeaderSaveData         = \"Save-Data\"\n\tHeaderViewportWidth    = \"Viewport-Width\"\n\tHeaderWidth            = \"Width\"\n\n\t// Conditionals\n\tHeaderETag              = \"ETag\"\n\tHeaderIfMatch           = \"If-Match\"\n\tHeaderIfModifiedSince   = \"If-Modified-Since\"\n\tHeaderIfNoneMatch       = \"If-None-Match\"\n\tHeaderIfUnmodifiedSince = \"If-Unmodified-Since\"\n\tHeaderLastModified      = \"Last-Modified\"\n\tHeaderVary              = \"Vary\"\n\n\t// Connection management\n\tHeaderConnection      = \"Connection\"\n\tHeaderKeepAlive       = \"Keep-Alive\"\n\tHeaderProxyConnection = \"Proxy-Connection\"\n\n\t// Content negotiation\n\tHeaderAccept         = \"Accept\"\n\tHeaderAcceptCharset  = \"Accept-Charset\"\n\tHeaderAcceptEncoding = \"Accept-Encoding\"\n\tHeaderAcceptLanguage = \"Accept-Language\"\n\n\t// Controls\n\tHeaderCookie      = \"Cookie\"\n\tHeaderExpect      = \"Expect\"\n\tHeaderMaxForwards = \"Max-Forwards\"\n\tHeaderSetCookie   = \"Set-Cookie\"\n\n\t// CORS\n\tHeaderAccessControlAllowCredentials = \"Access-Control-Allow-Credentials\"\n\tHeaderAccessControlAllowHeaders     = \"Access-Control-Allow-Headers\"\n\tHeaderAccessControlAllowMethods     = \"Access-Control-Allow-Methods\"\n\tHeaderAccessControlAllowOrigin      = \"Access-Control-Allow-Origin\"\n\tHeaderAccessControlExposeHeaders    = \"Access-Control-Expose-Headers\"\n\tHeaderAccessControlMaxAge           = \"Access-Control-Max-Age\"\n\tHeaderAccessControlRequestHeaders   = \"Access-Control-Request-Headers\"\n\tHeaderAccessControlRequestMethod    = \"Access-Control-Request-Method\"\n\tHeaderOrigin                        = \"Origin\"\n\tHeaderTimingAllowOrigin             = \"Timing-Allow-Origin\"\n\tHeaderXPermittedCrossDomainPolicies = \"X-Permitted-Cross-Domain-Policies\"\n\n\t// Do Not Track\n\tHeaderDNT = \"DNT\"\n\tHeaderTk  = \"Tk\"\n\n\t// Downloads\n\tHeaderContentDisposition = \"Content-Disposition\"\n\n\t// Message body information\n\tHeaderContentEncoding = \"Content-Encoding\"\n\tHeaderContentLanguage = \"Content-Language\"\n\tHeaderContentLength   = \"Content-Length\"\n\tHeaderContentLocation = \"Content-Location\"\n\tHeaderContentType     = \"Content-Type\"\n\n\t// Content Types\n\tContentTypeForm                   = \"application/x-www-form-urlencoded\" // https://datatracker.ietf.org/doc/html/rfc1866\n\tContentTypeMultipart              = \"multipart/form-data\"               // https://datatracker.ietf.org/doc/html/rfc2388\n\tContentTypeJSON                   = \"application/json\"                  // https://datatracker.ietf.org/doc/html/rfc4627\n\tContentTypeJSONUTF8               = \"application/json;charset=utf-8\"    // https://datatracker.ietf.org/doc/html/rfc4627\n\tContentTypeXML                    = \"application/xml\"                   // https://datatracker.ietf.org/doc/html/rfc3023\n\tContentTypeXMLUTF8                = \"application/xml;charset=utf-8\"\n\tContentTypeYAML                   = \"application/yaml\" // https://www.rfc-editor.org/rfc/rfc9512.html\n\tContentTypeYAMLUTF8               = \"application/yaml;charset=utf-8\"\n\tContentTypeText                   = \"text/plain\"\n\tContentTypeTextUTF8               = \"text/plain;charset=utf-8\"\n\tContentTypeApplicationOctetStream = \"application/octet-stream\"\n\n\t// Proxies\n\tHeaderForwarded       = \"Forwarded\"\n\tHeaderVia             = \"Via\"\n\tHeaderXForwardedFor   = \"X-Forwarded-For\"\n\tHeaderXForwardedHost  = \"X-Forwarded-Host\"\n\tHeaderXForwardedProto = \"X-Forwarded-Proto\"\n\n\t// Redirects\n\tHeaderLocation = \"Location\"\n\n\t// Request context\n\tHeaderFrom           = \"From\"\n\tHeaderHost           = \"Host\"\n\tHeaderReferer        = \"Referer\"\n\tHeaderReferrerPolicy = \"Referrer-Policy\"\n\tHeaderUserAgent      = \"User-Agent\"\n\n\t// Response context\n\tHeaderAllow  = \"Allow\"\n\tHeaderServer = \"Server\"\n\n\t// Range requests.\n\tHeaderAcceptRanges = \"Accept-Ranges\"\n\tHeaderContentRange = \"Content-Range\"\n\tHeaderIfRange      = \"If-Range\"\n\tHeaderRange        = \"Range\"\n\n\t// Security\n\tHeaderContentSecurityPolicy           = \"Content-Security-Policy\"\n\tHeaderContentSecurityPolicyReportOnly = \"Content-Security-Policy-Report-Only\"\n\tHeaderCrossOriginResourcePolicy       = \"Cross-Origin-Resource-Policy\"\n\tHeaderExpectCT                        = \"Expect-CT\"\n\tHeaderFeaturePolicy                   = \"Feature-Policy\"\n\tHeaderPublicKeyPins                   = \"Public-Key-Pins\"\n\tHeaderPublicKeyPinsReportOnly         = \"Public-Key-Pins-Report-Only\"\n\tHeaderStrictTransportSecurity         = \"Strict-Transport-Security\"\n\tHeaderUpgradeInsecureRequests         = \"Upgrade-Insecure-Requests\"\n\tHeaderXContentTypeOptions             = \"X-Content-Type-Options\"\n\tHeaderXDownloadOptions                = \"X-Download-Options\"\n\tHeaderXFrameOptions                   = \"X-Frame-Options\"\n\tHeaderXPoweredBy                      = \"X-Powered-By\"\n\tHeaderXXSSProtection                  = \"X-XSS-Protection\"\n\n\t// Server-sent event\n\tHeaderLastEventID = \"Last-Event-ID\"\n\tHeaderNEL         = \"NEL\"\n\tHeaderPingFrom    = \"Ping-From\"\n\tHeaderPingTo      = \"Ping-To\"\n\tHeaderReportTo    = \"Report-To\"\n\n\t// Transfer coding\n\tHeaderTE               = \"TE\"\n\tHeaderTrailer          = \"Trailer\"\n\tHeaderTransferEncoding = \"Transfer-Encoding\"\n\n\t// WebSockets\n\tHeaderSecWebSocketAccept     = \"Sec-WebSocket-Accept\"\n\tHeaderSecWebSocketExtensions = \"Sec-WebSocket-Extensions\" /* #nosec G101 */\n\tHeaderSecWebSocketKey        = \"Sec-WebSocket-Key\"\n\tHeaderSecWebSocketProtocol   = \"Sec-WebSocket-Protocol\"\n\tHeaderSecWebSocketVersion    = \"Sec-WebSocket-Version\"\n\n\t// Other\n\tHeaderAcceptPatch         = \"Accept-Patch\"\n\tHeaderAcceptPushPolicy    = \"Accept-Push-Policy\"\n\tHeaderAcceptSignature     = \"Accept-Signature\"\n\tHeaderAltSvc              = \"Alt-Svc\"\n\tHeaderDate                = \"Date\"\n\tHeaderIndex               = \"Index\"\n\tHeaderLargeAllocation     = \"Large-Allocation\"\n\tHeaderLink                = \"Link\"\n\tHeaderPushPolicy          = \"Push-Policy\"\n\tHeaderRetryAfter          = \"Retry-After\"\n\tHeaderServerTiming        = \"Server-Timing\"\n\tHeaderSignature           = \"Signature\"\n\tHeaderSignedHeaders       = \"Signed-Headers\"\n\tHeaderSourceMap           = \"SourceMap\"\n\tHeaderUpgrade             = \"Upgrade\"\n\tHeaderXDNSPrefetchControl = \"X-DNS-Prefetch-Control\"\n\tHeaderXPingback           = \"X-Pingback\"\n\tHeaderXRequestedWith      = \"X-Requested-With\"\n\tHeaderXRobotsTag          = \"X-Robots-Tag\"\n\tHeaderXUACompatible       = \"X-UA-Compatible\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrUnsupportedContentType is returned when the content type is unsupported\n\tErrUnsupportedContentType = errors.New(\"unsupported content type\")\n\t// ErrUnsuccessfulResponse is returned when the response is unsuccessful\n\tErrUnsuccessfulResponse = errors.New(\"unsuccessful response\")\n\t// ErrNoFilesUploaded is returned when no files are found in a multipart form request\n\tErrNoFilesUploaded = errors.New(\"no uploadable files found in request\")\n\t// ErrUnsupportedMimeType is returned when the mime type is unsupported\n\tErrUnsupportedMimeType = errors.New(\"unsupported mime type\")\n)\n```\n\n```go\nvar DefaultBackoff = ExponentialBackoff{\n\tBaseDelay:  1.0 * time.Second,\n\tMultiplier: 1.6,\n\tJitter:     0.2,\n\tMaxDelay:   120 * time.Second,\n}\n```\nDefaultBackoff is a backoff configuration with the default values\n\n```go\nvar DefaultRequester = Requester{}\n```\n\n```go\nvar DefaultRetryConfig = RetryConfig{}\n```\nDefaultRetryConfig is the default retry configuration used if nil is passed to Retry()\n\n## Functions\n\n```go\nfunc ChannelHandler() (chan\u003c- *http.Response, http.Handler)\n```\nChannelHandler returns an http.Handler and an input channel\n\n```go\nfunc DefaultShouldRetry(_ int, _ *http.Request, resp *http.Response, err error) bool\n```\nDefaultShouldRetry is the default ShouldRetryer\n\n```go\nfunc IsSuccess(resp *http.Response) bool\n```\nIsSuccess checks if the response status code indicates success\n\n```go\nfunc MockHandler(statusCode int, options ...Option) http.Handler\n```\nMockHandler returns an http.Handler which returns responses built from the args\n\n```go\nfunc MockResponse(statusCode int, options ...Option) *http.Response\n```\nMockResponse creates an \\*http.Response from the Options\n\n```go\nfunc OnlyIdempotentShouldRetry(_ int, req *http.Request, _ *http.Response, _ error) bool\n```\nOnlyIdempotentShouldRetry returns true if the request is using one of the HTTP methods which are intended to be idempotent: GET, HEAD, OPTIONS, and TRACE\n\n```go\nfunc Receive(into any, opts ...Option) (*http.Response, error)\n```\nReceive uses the DefaultRequester to create a request, execute it, and read the response\n\n```go\nfunc ReceiveInto[T any](opts ...Option) (*http.Response, T, error)\n```\nReceiveInto builds, sends and unmarshals into a typed value using the DefaultRequester.\n\n```go\nfunc ReceiveIntoWithContext[T any](ctx context.Context, opts ...Option) (*http.Response, T, error)\n```\nReceiveIntoWithContext does the same as ReceiveInto but with a context.\n\n```go\nfunc ReceiveTo(w io.Writer, opts ...Option) (*http.Response, int64, error)\n```\nReceiveTo streams the response body into the writer using the DefaultRequester.\n\n```go\nfunc ReceiveToWithContext(ctx context.Context, w io.Writer, opts ...Option) (*http.Response, int64, error)\n```\nReceiveToWithContext streams the response body into the writer with a context.\n\n```go\nfunc ReceiveWithContext(ctx context.Context, into any, opts ...Option) (*http.Response, error)\n```\nReceiveWithContext does the same as Receive(), but attaches a Context to the request\n\n```go\nfunc Request(opts ...Option) (*http.Request, error)\n```\nRequest uses the DefaultRequester to create a request\n\n```go\nfunc RequestWithContext(ctx context.Context, opts ...Option) (*http.Request, error)\n```\nRequestWithContext does the same as Request(), but attaches a Context to the request\n\n```go\nfunc Send(opts ...Option) (*http.Response, error)\n```\nSend uses the DefaultRequester to create a request and execute it\n\n```go\nfunc SendWithContext(ctx context.Context, opts ...Option) (*http.Response, error)\n```\nSendWithContext does the same as Send(), but attaches a Context to the request\n\n## Types\n\n```go\ntype Backoffer interface {\n\tBackoff(attempt int) time.Duration\n}\n```\nBackoffer calculates how long to wait between attempts\n\n```go\ntype BackofferFunc func(int) time.Duration\n```\nBackofferFunc adapts a function to the Backoffer interface\n\n```go\nfunc (b BackofferFunc) Backoff(attempt int) time.Duration\n```\nBackoff implements Backoffer\n\n```go\ntype ContentTypeUnmarshaler struct {\n\tUnmarshalers map[string]Unmarshaler\n}\n```\nContentTypeUnmarshaler selects an unmarshaler based on the content type\n\n```go\nfunc NewContentTypeUnmarshaler() *ContentTypeUnmarshaler\n```\nNewContentTypeUnmarshaler returns a new ContentTypeUnmarshaler preconfigured to handle application/json and application/xml\n\n```go\nfunc (c *ContentTypeUnmarshaler) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\nfunc (c *ContentTypeUnmarshaler) Unmarshal(data []byte, contentType string, v any) error\n```\nUnmarshal implements Unmarshaler\n\n```go\ntype Doer interface {\n\tDo(req *http.Request) (*http.Response, error)\n}\n```\nDoer executes http requests\n\n```go\nfunc Wrap(d Doer, m ...Middleware) Doer\n```\nWrap applies a set of middleware to a Doer.  The returned Doer will invoke the middleware in the order of the arguments.\n\n```go\ntype DoerFunc func(req *http.Request) (*http.Response, error)\n```\nDoerFunc adapts a function to implement Doer\n\n```go\nfunc ChannelDoer() (chan\u003c- *http.Response, DoerFunc)\n```\nChannelDoer returns a DoerFunc and a channel\n\n```go\nfunc MockDoer(statusCode int, options ...Option) DoerFunc\n```\nMockDoer creates a Doer which returns a mocked response, for writing tests\n\n```go\nfunc (f DoerFunc) Apply(r *Requester) error\n```\nApply implements the Option interface\n\n```go\nfunc (f DoerFunc) Do(req *http.Request) (*http.Response, error)\n```\nDo implements the Doer interface\n\n```go\ntype ErrResponseHandler func(error) http.HandlerFunc\n```\nErrResponseHandler is a custom error that should be used to handle errors when an upload fails\n\n```go\ntype ExponentialBackoff struct {\n\t// BaseDelay is the amount of time to backoff after the first failure\n\tBaseDelay time.Duration\n\t// Multiplier is the factor with which to multiply backoffs after a failed retry\n\tMultiplier float64\n\t// Jitter is the factor with which backoffs are randomized\n\tJitter float64\n\t// MaxDelay is the upper bound of backoff delay - 0 means no max\n\tMaxDelay time.Duration\n}\n```\nExponentialBackoff defines the configuration options for an exponential backoff strategy\n\n```go\nfunc ConstantBackoff(delay time.Duration) *ExponentialBackoff\n```\nConstantBackoff returns a Backoffer with a fixed, constant delay between retries and no jitter\n\n```go\nfunc ConstantBackoffWithJitter(delay time.Duration) *ExponentialBackoff\n```\nConstantBackoffWithJitter returns a Backoffer with a fixed, constant delay between retries with 20% jitter\n\n```go\nfunc NoBackoff() *ExponentialBackoff\n```\nNoBackoff returns a Backoffer with zero backoff, and zero delay between retries\n\n```go\nfunc (c *ExponentialBackoff) Backoff(attempt int) time.Duration\n```\n\n```go\ntype File struct {\n\t// FieldName denotes the field from the multipart form\n\tFieldName string `json:\"field_name,omitempty\"`\n\t// OriginalName is he name of the file from the client side / which was sent in the request\n\tOriginalName string `json:\"original_name,omitempty\"`\n\t// MimeType of the uploaded file\n\tMimeType string `json:\"mime_type,omitempty\"`\n\t// Size in bytes of the uploaded file\n\tSize int64 `json:\"size,omitempty\"`\n}\n```\nFile represents a file that has been sent in an http request\n\n```go\nfunc FilesFromContextWithKey(r *http.Request, key string) ([]File, error)\n```\nFilesFromContextWithKey returns  all files that have been uploaded during the request and sorts by the provided form field\n\n```go\ntype Files map[string][]File\n```\nFiles is a map of form field names to a slice of files\n\n```go\nfunc FilesFromContext(r *http.Request, key string) (Files, error)\n```\nFilesFromContext returns all files that have been uploaded during the request\n\n```go\ntype FormMarshaler struct{}\n```\nFormMarshaler implements Marshaler\n\n```go\nfunc (m *FormMarshaler) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\nfunc (*FormMarshaler) Marshal(v any) (data []byte, contentType string, err error)\n```\nMarshal implements Marshaler\n\n```go\ntype Inspector struct {\n\t// The last request sent by the client\n\tRequest *http.Request\n\t// The last response received by the client\n\tResponse *http.Response\n\t// The last client request body\n\tRequestBody *bytes.Buffer\n\t// The last client response body\n\tResponseBody *bytes.Buffer\n}\n```\nInspector is a Requester Option which captures requests and responses\n\n```go\nfunc Inspect(r *Requester) *Inspector\n```\nInspect installs and returns an Inspector\n\n```go\nfunc (i *Inspector) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\nfunc (i *Inspector) Clear()\n```\nClear clears the inspector's fields\n\n```go\nfunc (i *Inspector) Wrap(next Doer) Doer\n```\nWrap implements Middleware\n\n```go\ntype JSONMarshaler struct {\n\tIndent bool\n}\n```\nJSONMarshaler implement Marshaler and Unmarshaler\n\n```go\nfunc (m *JSONMarshaler) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\nfunc (m *JSONMarshaler) Marshal(v any) (data []byte, contentType string, err error)\n```\nMarshal implements Marshaler\n\n```go\nfunc (m *JSONMarshaler) Unmarshal(data []byte, _ string, v any) error\n```\nUnmarshal implements Unmarshaler\n\n```go\ntype MarshalFunc func(v any) ([]byte, string, error)\n```\nMarshalFunc adapts a function to the Marshaler interface\n\n```go\nfunc (f MarshalFunc) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\nfunc (f MarshalFunc) Marshal(v any) ([]byte, string, error)\n```\nMarshal implements the Marshaler interface\n\n```go\ntype Marshaler interface {\n\tMarshal(v any) (data []byte, contentType string, err error)\n}\n```\nMarshaler marshals values into a \\[]byte\n\n```go\nvar DefaultMarshaler Marshaler = \u0026JSONMarshaler{}\n```\n\n```go\ntype Middleware func(Doer) Doer\n```\nMiddleware can be used to wrap Doers with additional functionality.\n\n```go\nfunc Dump(w io.Writer) Middleware\n```\nDump dumps requests and responses to a writer.  Just intended for debugging.\n\n```go\nfunc DumpToLog(logf func(a ...any)) Middleware\n```\nDumpToLog dumps the request and response to a logging function. logf is compatible with fmt.Print(), testing.T.Log, or log.XXX() functions.\n\nlogf will be invoked once for the request, and once for the response. Each invocation will only have a single argument (the entire request or response is logged as a single string value).\n\n```go\nfunc DumpToStderr() Middleware\n```\nDumpToStderr dumps requests and responses to os.Stderr\n\n```go\nfunc DumpToStdout() Middleware\n```\nDumpToStdout dumps requests and responses to os.Stdout. This is a correctly spelled alias of DumpToStout.\n\n```go\nfunc DumpToStout() Middleware\n```\nDumpToStout dumps requests and responses to os.Stdout Deprecated: use DumpToStdout instead.\n\n```go\nfunc ExpectCode(code int) Middleware\n```\nExpectCode generates an error if the response's status code does not match the expected code.\n\nThe response body will still be read and returned.\n\n```go\nfunc ExpectCodes(codes ...int) Middleware\n```\nExpectCodes generates an error if the response's status code does not match any of the provided codes. If no codes are provided, it behaves like ExpectSuccessCode. The response body is still read and returned.\n\n```go\nfunc ExpectSuccessCode() Middleware\n```\nExpectSuccessCode is middleware which generates an error if the response's status code is not between 200 and 299.\n\nThe response body will still be read and returned.\n\n```go\nfunc Retry(config *RetryConfig) Middleware\n```\nRetry retries the http request under certain conditions - the number of retries, retry conditions, and the time to sleep between retries can be configured\n\n```go\nfunc (m Middleware) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\ntype NameGeneratorFunc func(s string) string\n```\nNameGeneratorFunc allows you alter the name of the file before it is ultimately uploaded and stored\n\n```go\ntype Option interface {\n\tApply(*Requester) error\n}\n```\nOption applies some setting to a Requester object\n\n```go\nfunc Accept(accept string) Option\n```\nAccept sets the Accept header\n\n```go\nfunc AddHeader(key, value string) Option\n```\nAddHeader adds a header value, using Header.Add()\n\n```go\nfunc AppendPath(elements ...string) Option\n```\nAppendPath appends path elements to the end of the URL.Path\n\n```go\nfunc BasicAuth(username, password string) Option\n```\nBasicAuth sets the Authorization header to \"Basic \\\u003cencoded username and password\u003e\"\n\n```go\nfunc BearerAuth(token string) Option\n```\nBearerAuth sets the Authorization header to \"Bearer \\\u003ctoken\u003e\"\n\n```go\nfunc Body(body any) Option\n```\nBody sets the body of the request\n\n```go\nfunc Client(opts ...httpclient.Option) Option\n```\nClient replaces Requester.Doer with an \\*http.Client\n\n```go\nfunc ContentType(contentType string) Option\n```\nContentType sets the Content-Type header\n\n```go\nfunc Delete(paths ...string) Option\n```\nDelete sets the HTTP method to \"DELETE\"\n\n```go\nfunc DeleteHeader(key string) Option\n```\nDeleteHeader deletes a header key, using Header.Del()\n\n```go\nfunc Form() Option\n```\nForm sets Requester.Marshaler to the FormMarshaler which marshals the body into form-urlencoded\n\n```go\nfunc Get(paths ...string) Option\n```\nGet sets the HTTP method to \"GET\"\n\n```go\nfunc Head(paths ...string) Option\n```\nHead sets the HTTP method to \"HEAD\"\n\n```go\nfunc Header(key, value string) Option\n```\nHeader sets a header value, using Header.Set()\n\n```go\nfunc HeadersFromMap(m map[string]string) Option\n```\nHeadersFromMap sets multiple headers from a simple string map using Header.Set semantics.\n\n```go\nfunc HeadersFromValues(h http.Header) Option\n```\nHeadersFromValues sets multiple headers from an http.Header map using Header.Set semantics.\n\n```go\nfunc Host(host string) Option\n```\nHost sets Requester.Host\n\n```go\nfunc JSON(indent bool) Option\n```\nJSON sets Requester.Marshaler to the JSONMarshaler\n\n```go\nfunc JSONBody(v any) Option\n```\nJSONBody sets JSON marshaling and attaches the given body value.\n\n```go\nfunc Method(m string, paths ...string) Option\n```\nMethod sets the HTTP method\n\n```go\nfunc Patch(paths ...string) Option\n```\nPatch sets the HTTP method to \"PATCH\"\n\n```go\nfunc Post(paths ...string) Option\n```\nPost sets the HTTP method to \"POST\"\n\n```go\nfunc Put(paths ...string) Option\n```\nPut sets the HTTP method to \"PUT\"\n\n```go\nfunc QueryParam(k, v string) Option\n```\nQueryParam adds a query parameter\n\n```go\nfunc QueryParams(queryStructs ...any) Option\n```\nQueryParams adds params to the Requester.QueryParams member\n\n```go\nfunc Range(byteRange string) Option\n```\nRange sets the Range header\n\n```go\nfunc RelativeURL(paths ...string) Option\n```\nRelativeURL resolves the arg as a relative URL references against the current URL, using the standard lib's url.URL.ResolveReference() method\n\n```go\nfunc URL(rawurl string) Option\n```\nURL sets the request URL\n\n```go\nfunc Use(m ...Middleware) Option\n```\nUse appends middleware to Requester.Middleware\n\n```go\nfunc WithDoer(d Doer) Option\n```\nWithDoer replaces Requester.Doer\n\n```go\nfunc WithFileErrorResponseHandler(errHandler ErrResponseHandler) Option\n```\nWithFileErrorResponseHandler allows you to configure how you'd like to handle errors when a file upload fails either to your own server or the destination server or both\n\n```go\nfunc WithHTTPClient(c *http.Client) Option\n```\nWithHTTPClient replaces Requester.Doer with the given \\*http.Client.\n\n```go\nfunc WithMarshaler(m Marshaler) Option\n```\nWithMarshaler sets Requester.WithMarshaler\n\n```go\nfunc WithMaxFileSize(i int64) Option\n```\nWithMaxFileSize sets the maximum file size for file uploads\n\n```go\nfunc WithNameFuncGenerator(nameFunc NameGeneratorFunc) Option\n```\nWithNameFuncGenerator allows you configure how you'd like to rename your uploaded files\n\n```go\nfunc WithUnmarshaler(m Unmarshaler) Option\n```\nWithUnmarshaler sets Requester.WithUnmarshaler\n\n```go\nfunc WithValidationFunc(validationFunc ValidationFunc) Option\n```\nWithValidationFunc allows you to set a function that can be used to perform validations\n\n```go\nfunc XML(indent bool) Option\n```\nXML sets Requester.Marshaler to the XMLMarshaler\n\n```go\ntype OptionFunc func(*Requester) error\n```\nOptionFunc adapts a function to the Option interface\n\n```go\nfunc (f OptionFunc) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\ntype Requester struct {\n\t// Method is the HTTP method to use for the request\n\tMethod string\n\t// URL is the URL to request\n\tURL *url.URL\n\t// Header supplies the request headers; note: if a Marshaler provides a Content-Type,\n\t// it will override any Content-Type set here when building the http.Request\n\tHeader http.Header\n\t// GetBody is a function that returns a ReadCloser for the request body\n\tGetBody func() (io.ReadCloser, error)\n\t// ContentLength is the length of the request body\n\tContentLength int64\n\t// TransferEncoding is the transfer encoding for the request body\n\tTransferEncoding []string\n\t// Close indicates whether the connection should be closed after the request\n\tClose bool\n\t// Host is the host to use for the request\n\tHost string\n\t// Trailer is the trailer for the request\n\tTrailer http.Header\n\t// QueryParams are added to the request, in addition to any query params already encoded in the URL\n\tQueryParams url.Values\n\t// Body can be set to a string, []byte, io.Reader, or a struct; if set to a string, []byte, or io.Reader, the value will be used as the body of the request\n\t// If set to a struct, the Marshaler will be used to marshal the value into the request body\n\tBody any\n\t// Marshaler will be used to marshal the Body value into the body of the request.\n\tMarshaler Marshaler\n\t// Doer holds the HTTP client for used to execute httpsling\n\tDoer Doer\n\t// Middleware wraps the Doer\n\tMiddleware []Middleware\n\t// Unmarshaler will be used by the Receive methods to unmarshal the response body\n\tUnmarshaler Unmarshaler\n\t// MaxFileSize is the maximum size of a file to download\n\tMaxFileSize int64\n\t// contains filtered or unexported fields\n}\n```\nRequester is a struct that contains the information needed to make an HTTP request\n\n```go\nfunc MustNew(options ...Option) *Requester\n```\nMustNew creates a new Requester, applying all options\n\n```go\nfunc New(options ...Option) (*Requester, error)\n```\nNew returns a new Requester, applying all options\n\n```go\nfunc (r *Requester) Apply(opts ...Option) error\n```\nApply applies the options to the receiver\n\n```go\nfunc (r *Requester) Clone() *Requester\n```\nClone returns a deep copy of a Requester\n\n```go\nfunc (r *Requester) CookieJar() http.CookieJar\n```\nCookieJar returns the CookieJar used by the Requester, if it exists\n\n```go\nfunc (r *Requester) Do(req *http.Request) (*http.Response, error)\n```\nDo implements Doer\n\n```go\nfunc (r *Requester) HTTPClient() *http.Client\n```\nHTTPClient returns the HTTP client used by the Requester\n\n```go\nfunc (r *Requester) Headers() http.Header\n```\nHeaders returns the Header\n\n```go\nfunc (r *Requester) MustApply(opts ...Option)\n```\nMustApply applies the options to the receiver\n\n```go\nfunc (r *Requester) MustWith(opts ...Option) *Requester\n```\nMustWith clones the Requester, then applies the options to the clone\n\n```go\nfunc (r *Requester) Params() url.Values\n```\nParams returns the QueryParams\n\n```go\nfunc (r *Requester) Receive(into any, opts ...Option) (resp *http.Response, err error)\n```\nReceive creates a new HTTP request and returns the response\n\n```go\nfunc (r *Requester) ReceiveTo(ctx context.Context, w io.Writer, opts ...Option) (*http.Response, int64, error)\n```\nReceiveTo streams the response body to the provided writer without buffering the entire response in memory. It returns the response and the number of bytes copied. The response body is fully consumed and closed by this method.\n\n```go\nfunc (r *Requester) ReceiveWithContext(ctx context.Context, into any, opts ...Option) (resp *http.Response, err error)\n```\nReceiveWithContext does the same as Receive, but requires a context\n\n```go\nfunc (r *Requester) Request(opts ...Option) (*http.Request, error)\n```\nRequest returns a new http.Request\n\n```go\nfunc (r *Requester) RequestWithContext(ctx context.Context, opts ...Option) (*http.Request, error)\n```\nRequestWithContext does the same as Request, but requires a context\n\n```go\nfunc (r *Requester) Send(opts ...Option) (*http.Response, error)\n```\nSend executes a request with the Doer\n\n```go\nfunc (r *Requester) SendWithContext(ctx context.Context, opts ...Option) (*http.Response, error)\n```\nSendWithContext does the same as Send, but requires a context\n\n```go\nfunc (r *Requester) Trailers() http.Header\n```\nTrailers returns the Trailer, initializing it if necessary\n\n```go\nfunc (r *Requester) With(opts ...Option) (*Requester, error)\n```\nWith clones the Requester, then applies the options to the clone\n\n```go\ntype RetryConfig struct {\n\t// MaxAttempts is the number of times to attempt the request (default 3)\n\tMaxAttempts int\n\t// ShouldRetry tests whether a response should be retried\n\tShouldRetry ShouldRetryer\n\t// Backoff returns how long to wait between retries\n\tBackoff Backoffer\n\t// ReadResponse will ensure the entire response is read before considering the request a success\n\tReadResponse bool\n}\n```\nRetryConfig defines settings for the Retry middleware\n\n```go\ntype ShouldRetryer interface {\n\tShouldRetry(attempt int, req *http.Request, resp *http.Response, err error) bool\n}\n```\nShouldRetryer evaluates whether an HTTP request should be retried\n\n```go\nfunc AllRetryers(s ...ShouldRetryer) ShouldRetryer\n```\nAllRetryers returns a ShouldRetryer which returns true only if all the supplied retryers return true\n\n```go\ntype ShouldRetryerFunc func(attempt int, req *http.Request, resp *http.Response, err error) bool\n```\nShouldRetryerFunc adapts a function to the ShouldRetryer interface\n\n```go\nfunc (s ShouldRetryerFunc) ShouldRetry(attempt int, req *http.Request, resp *http.Response, err error) bool\n```\nShouldRetry implements ShouldRetryer\n\n```go\ntype TextUnmarshaler struct {\n\tIndent bool\n}\n```\nTextUnmarshaler implements Marshaler and Unmarshaler\n\n```go\nfunc (m *TextUnmarshaler) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\nfunc (m *TextUnmarshaler) Marshal(v any) (data []byte, contentType string, err error)\n```\nMarshal implements Marshaler\n\n```go\nfunc (*TextUnmarshaler) Unmarshal(data []byte, _ string, v any) error\n```\nUnmarshal implements Unmarshaler\n\n```go\ntype UnmarshalFunc func(data []byte, contentType string, v any) error\n```\nUnmarshalFunc adapts a function to the Unmarshaler interface\n\n```go\nfunc (f UnmarshalFunc) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\nfunc (f UnmarshalFunc) Unmarshal(data []byte, contentType string, v any) error\n```\nUnmarshal implements the Unmarshaler interface\n\n```go\ntype Unmarshaler interface {\n\tUnmarshal(data []byte, contentType string, v any) error\n}\n```\nUnmarshaler unmarshals a \\[]byte response body into a value\n\n```go\nvar DefaultUnmarshaler Unmarshaler = NewContentTypeUnmarshaler()\n```\n\n```go\ntype ValidationFunc func(f File) error\n```\nValidationFunc is a type that can be used to dynamically validate a file\n\n```go\nfunc ChainValidators(validators ...ValidationFunc) ValidationFunc\n```\nChainValidators returns a validator that accepts multiple validating criteria\n\n```go\nfunc MimeTypeValidator(validMimeTypes ...string) ValidationFunc\n```\nMimeTypeValidator makes sure we only accept a valid mimetype. It takes in an array of supported mimes\n\n```go\ntype XMLMarshaler struct {\n\tIndent bool\n}\n```\nXMLMarshaler implements Marshaler and Unmarshaler\n\n```go\nfunc (m *XMLMarshaler) Apply(r *Requester) error\n```\nApply implements Option\n\n```go\nfunc (m *XMLMarshaler) Marshal(v any) (data []byte, contentType string, err error)\n```\nMarshal implements Marshaler\n\n```go\nfunc (*XMLMarshaler) Unmarshal(data []byte, _ string, v any) error\n```\nUnmarshal implements Unmarshaler\n\n","path":"github.com/theopenlane/httpsling","name":"httpsling","synopsis":"Package httpsling is a wrapper for creating and sending http httpsling (e.g.","isRedistributable":true}
