httpx

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisallowIPPrivateAddresses

func DisallowIPPrivateAddresses(ipOrHostnameOrURL string) error

DisallowIPPrivateAddresses returns nil for a domain (with NS lookup), IP, or IPv6 address if it does not resolve to a private IP subnet. This is a first level of defense against SSRF attacks by disallowing any domain or IP to resolve to a private network range.

Please keep in mind that validations for domains is valid only when looking up. A malicious actor could easily update the DSN record post validation to point to an internal IP

func DisallowPrivateIPAddressesWhenSet

func DisallowPrivateIPAddressesWhenSet(ipOrHostnameOrURL string) error

DisallowPrivateIPAddressesWhenSet is a wrapper for DisallowIPPrivateAddresses which returns valid when ipOrHostnameOrURL is empty.

func GetResponseMeta

func GetResponseMeta(w http.ResponseWriter) (status, size int)

func HasContentType

func HasContentType(r *http.Request, mimetypes ...string) bool

HasContentType determines whether the request `content-type` includes a server-acceptable mime-type

Failure should yield an HTTP 415 (`http.StatusUnsupportedMediaType`)

func IncomingRequestURL

func IncomingRequestURL(r *http.Request) *url.URL

IncomingRequestURL returns the URL of the incoming HTTP request by looking at the host, TLS, and X-Forwarded-* headers.

func MustNewRequest

func MustNewRequest(method, url string, body io.Reader, contentType string) *http.Request

MustNewRequest returns a new *http.Request or fatals.

func NewChanHandler

func NewChanHandler(buf int) (http.Handler, chan<- http.HandlerFunc)

NewChanHandler returns a new handler and corresponding channel for sending handler funcs. Useful for testing. The argument buf specifies the channel capacity, so pass 0 for a sync handler.

func NewRequestForm

func NewRequestForm(method, url string, data url.Values) (*http.Request, error)

NewRequestForm returns a new POST Form *http.Request.

func NewRequestJSON

func NewRequestJSON(method, url string, data interface{}) (*http.Request, error)

NewRequestJSON returns a new JSON *http.Request.

func NewResilientClient

func NewResilientClient(opts ...ResilientOptions) *retryablehttp.Client

NewResilientClient creates a new ResilientClient.

func WaitForEndpoint

func WaitForEndpoint(ctx context.Context, endpoint string, opts ...retry.Option) error

WaitForEndpoint waits for the endpoint to be available.

func WaitForEndpointWithClient

func WaitForEndpointWithClient(ctx context.Context, client *http.Client, endpoint string, opts ...retry.Option) error

WaitForEndpointWithClient waits for the endpoint to be available while using the given http.Client.

Types

type CompressionRequestReader

type CompressionRequestReader struct {
	ErrHandler func(w http.ResponseWriter, r *http.Request, err error)
}

func NewCompressionRequestReader

func NewCompressionRequestReader(eh func(w http.ResponseWriter, r *http.Request, err error)) *CompressionRequestReader

func (*CompressionRequestReader) ServeHTTP

type ErrPrivateIPAddressDisallowed

type ErrPrivateIPAddressDisallowed error

ErrPrivateIPAddressDisallowed is returned when a private IP address is disallowed.

type NoInternalIPRoundTripper

type NoInternalIPRoundTripper struct {
	http.RoundTripper
}

NoInternalIPRoundTripper is a RoundTripper that disallows internal IP addresses.

func (NoInternalIPRoundTripper) RoundTrip

func (n NoInternalIPRoundTripper) RoundTrip(request *http.Request) (*http.Response, error)

type ResilientOptions

type ResilientOptions func(o *resilientOptions)

ResilientOptions is a set of options for the ResilientClient.

func ResilientClientDisallowInternalIPs

func ResilientClientDisallowInternalIPs() ResilientOptions

ResilientClientDisallowInternalIPs disallows internal IPs from being used.

func ResilientClientWithClient

func ResilientClientWithClient(c *http.Client) ResilientOptions

ResilientClientWithClient sets the underlying http client to use.

func ResilientClientWithConnectionTimeout

func ResilientClientWithConnectionTimeout(connTimeout time.Duration) ResilientOptions

ResilientClientWithConnectionTimeout sets the connection timeout for the client.

func ResilientClientWithLogger

func ResilientClientWithLogger(l *logrusx.Logger) ResilientOptions

ResilientClientWithLogger sets the logger to be used by the client.

func ResilientClientWithMaxRetry

func ResilientClientWithMaxRetry(retryMax int) ResilientOptions

ResilientClientWithMaxRetry sets the maximum number of retries.

func ResilientClientWithMaxRetryWait

func ResilientClientWithMaxRetryWait(retryWaitMax time.Duration) ResilientOptions

ResilientClientWithMaxRetryWait sets the maximum wait time for a retry.

func ResilientClientWithMinxRetryWait

func ResilientClientWithMinxRetryWait(retryWaitMin time.Duration) ResilientOptions

ResilientClientWithMinxRetryWait sets the minimum wait time between retries.

func ResilientClientWithTracer

func ResilientClientWithTracer(tracer trace.Tracer) ResilientOptions

ResilientClientWithTracer wraps the http clients transport with a tracing instrumentation

type TransportWithHeader

type TransportWithHeader struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

TransportWithHeader is an http.RoundTripper that always uses the values from the given header.

func NewTransportWithHeader

func NewTransportWithHeader(h http.Header) *TransportWithHeader

NewTransportWithHeader returns a new http.Transport that always uses the values from the given header.

func (*TransportWithHeader) RoundTrip

func (ct *TransportWithHeader) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type TransportWithHost

type TransportWithHost struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

TransportWithHost is an http.RoundTripper that always uses the given host.

func NewTransportWithHost

func NewTransportWithHost(host string) *TransportWithHost

NewTransportWithHost returns a new http.Transport that always uses the given host.

func WrapRoundTripperWithHost

func WrapRoundTripperWithHost(parent http.RoundTripper, host string) *TransportWithHost

WrapRoundTripperWithHost wraps a http.RoundTripper that always uses the given host.

func (*TransportWithHost) RoundTrip

func (ct *TransportWithHost) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

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