httpx

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 22 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientFromContext

func ClientFromContext(ctx context.Context) (*http.Client, bool)

func DisableKeepAlivesClient

func DisableKeepAlivesClient() *http.Client

DisableKeepAlivesClient returns a new http.Client with similar default values to http.Client, but with a non-shared Transport, idle connections disabled, and keepalives disabled.

func DisableKeepAlivesTransport

func DisableKeepAlivesTransport() *http.Transport

DisableKeepAlivesTransport returns a new http.Transport with similar default values to http.DefaultTransport, but with idle connections and keepalives disabled.

func NewContextWithClient

func NewContextWithClient(ctx context.Context, cli *http.Client) context.Context

func NewContextWithRequest

func NewContextWithRequest(ctx context.Context, req *http.Request) context.Context

func NewContextWithResponse

func NewContextWithResponse(ctx context.Context, resp *http.Response) context.Context

func PooledClient

func PooledClient() *http.Client

PooledClient returns a new http.Client with similar default values to http.Client, but with a shared Transport. Do not use this function for transient clients as it can leak file descriptors over time. Only use this for clients that will be re-used for the same host(s).

func PooledTransport

func PooledTransport() *http.Transport

PooledTransport returns a new http.Transport with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).

func RequestFromContext

func RequestFromContext(ctx context.Context) (*http.Request, bool)

func ResponseFromContext

func ResponseFromContext(ctx context.Context) (*http.Response, bool)

Types

type ClientBuilder

type ClientBuilder struct {
	// contains filtered or unexported fields
}

func (*ClientBuilder) Build

func (builder *ClientBuilder) Build() *http.Client

func (*ClientBuilder) CheckRedirect

func (builder *ClientBuilder) CheckRedirect(f func(req *http.Request, via []*http.Request) error) *ClientBuilder

func (*ClientBuilder) Jar

func (builder *ClientBuilder) Jar(jar http.CookieJar) *ClientBuilder

func (*ClientBuilder) Timeout

func (builder *ClientBuilder) Timeout(timeout time.Duration) *ClientBuilder

func (*ClientBuilder) Transport

func (builder *ClientBuilder) Transport(transport http.RoundTripper) *ClientBuilder

type CompositeHandler added in v1.1.0

type CompositeHandler struct {
	// contains filtered or unexported fields
}

func (*CompositeHandler) AddHandler added in v1.1.0

func (h *CompositeHandler) AddHandler(handler http.Handler, match func(request *http.Request) bool)

func (*CompositeHandler) ServeHTTP added in v1.1.0

func (h *CompositeHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type DoCommand

type DoCommand struct{}

func (*DoCommand) Execute

func (cmd *DoCommand) Execute(ctx context.Context) (context.Context, error)

type FormData

type FormData struct {
	FieldName string
	Value     string
	File      io.Reader
	Filename  string
}

type RequestBuilder

type RequestBuilder struct {
	// contains filtered or unexported fields
}

func NewRequestBuilder added in v1.0.7

func NewRequestBuilder() *RequestBuilder

func (*RequestBuilder) APIKey

func (builder *RequestBuilder) APIKey(key string, value string) *RequestBuilder

func (*RequestBuilder) AddCookie

func (builder *RequestBuilder) AddCookie(cookie *http.Cookie) *RequestBuilder

func (*RequestBuilder) AddHeader

func (builder *RequestBuilder) AddHeader(name, value string) *RequestBuilder

func (*RequestBuilder) AddQuery

func (builder *RequestBuilder) AddQuery(key, value string) *RequestBuilder

func (*RequestBuilder) BasicAuth

func (builder *RequestBuilder) BasicAuth(username, password string) *RequestBuilder

func (*RequestBuilder) BearerAuth

func (builder *RequestBuilder) BearerAuth(token string) *RequestBuilder

func (*RequestBuilder) Body

func (builder *RequestBuilder) Body(body io.Reader, contentType string) *RequestBuilder

func (*RequestBuilder) Build

func (builder *RequestBuilder) Build(ctx context.Context) (*http.Request, error)

func (*RequestBuilder) BytesBody

func (builder *RequestBuilder) BytesBody(body []byte, contentType string) *RequestBuilder

func (*RequestBuilder) CacheControl

func (builder *RequestBuilder) CacheControl(directives ...string) *RequestBuilder

func (*RequestBuilder) Connect

func (builder *RequestBuilder) Connect() *RequestBuilder

func (*RequestBuilder) Cookie

func (builder *RequestBuilder) Cookie(cookie *http.Cookie) *RequestBuilder

func (*RequestBuilder) Cookies

func (builder *RequestBuilder) Cookies(cookies ...*http.Cookie) *RequestBuilder

func (*RequestBuilder) CustomAuth

func (builder *RequestBuilder) CustomAuth(scheme, token string) *RequestBuilder

func (*RequestBuilder) Delete

func (builder *RequestBuilder) Delete() *RequestBuilder

func (*RequestBuilder) Execute added in v1.0.6

func (builder *RequestBuilder) Execute(ctx context.Context, cli *http.Client) *ResponseHelper

func (*RequestBuilder) FormBody

func (builder *RequestBuilder) FormBody(form url.Values) *RequestBuilder

func (*RequestBuilder) Get

func (builder *RequestBuilder) Get() *RequestBuilder

func (*RequestBuilder) GobBody

func (builder *RequestBuilder) GobBody(body any) *RequestBuilder

func (*RequestBuilder) Head

func (builder *RequestBuilder) Head() *RequestBuilder

func (*RequestBuilder) Header

func (builder *RequestBuilder) Header(name, value string) *RequestBuilder

func (*RequestBuilder) Headers

func (builder *RequestBuilder) Headers(header http.Header) *RequestBuilder

func (*RequestBuilder) IfMatch

func (builder *RequestBuilder) IfMatch(etags ...string) *RequestBuilder

func (*RequestBuilder) IfModifiedSince

func (builder *RequestBuilder) IfModifiedSince(time string) *RequestBuilder

func (*RequestBuilder) IfNoneMatch

func (builder *RequestBuilder) IfNoneMatch(etag string) *RequestBuilder

func (*RequestBuilder) IfUnmodifiedSince

func (builder *RequestBuilder) IfUnmodifiedSince(time string) *RequestBuilder

func (*RequestBuilder) JSONBody

func (builder *RequestBuilder) JSONBody(body any) *RequestBuilder

func (*RequestBuilder) Method

func (builder *RequestBuilder) Method(method string) *RequestBuilder

func (*RequestBuilder) MultipartBody

func (builder *RequestBuilder) MultipartBody(formData ...*FormData) *RequestBuilder

func (*RequestBuilder) ObjectBody

func (builder *RequestBuilder) ObjectBody(body any, marshal func(any) ([]byte, error), contentType string) *RequestBuilder

func (*RequestBuilder) Options

func (builder *RequestBuilder) Options() *RequestBuilder

func (*RequestBuilder) Patch

func (builder *RequestBuilder) Patch() *RequestBuilder

func (*RequestBuilder) Post

func (builder *RequestBuilder) Post() *RequestBuilder

func (*RequestBuilder) ProtobufBody

func (builder *RequestBuilder) ProtobufBody(body proto.Message) *RequestBuilder

func (*RequestBuilder) Put

func (builder *RequestBuilder) Put() *RequestBuilder

func (*RequestBuilder) Queries

func (builder *RequestBuilder) Queries(queries url.Values) *RequestBuilder

func (*RequestBuilder) Query

func (builder *RequestBuilder) Query(name, value string) *RequestBuilder

func (*RequestBuilder) QueryString

func (builder *RequestBuilder) QueryString(q string) *RequestBuilder

func (*RequestBuilder) RemoveCookie

func (builder *RequestBuilder) RemoveCookie(cookie *http.Cookie) *RequestBuilder

func (*RequestBuilder) RemoveHeader

func (builder *RequestBuilder) RemoveHeader(name string) *RequestBuilder

func (*RequestBuilder) RemoveQuery

func (builder *RequestBuilder) RemoveQuery(name string) *RequestBuilder

func (*RequestBuilder) TextBody

func (builder *RequestBuilder) TextBody(body string, contentType string) *RequestBuilder

func (*RequestBuilder) Trace

func (builder *RequestBuilder) Trace() *RequestBuilder

func (*RequestBuilder) URL

func (builder *RequestBuilder) URL(uri *url.URL) *RequestBuilder

func (*RequestBuilder) URLString

func (builder *RequestBuilder) URLString(urlString string) *RequestBuilder

func (*RequestBuilder) UserAgent

func (builder *RequestBuilder) UserAgent(ua string) *RequestBuilder

func (*RequestBuilder) XMLBody

func (builder *RequestBuilder) XMLBody(body any) *RequestBuilder

type ResponseHelper

type ResponseHelper struct {
	// contains filtered or unexported fields
}

func NewResponseHelper added in v1.0.3

func NewResponseHelper(resp *http.Response, err error) *ResponseHelper

func (*ResponseHelper) Body

func (helper *ResponseHelper) Body() (io.ReadCloser, error)

func (*ResponseHelper) BytesBody

func (helper *ResponseHelper) BytesBody() ([]byte, error)

func (*ResponseHelper) Cookies

func (helper *ResponseHelper) Cookies() ([]*http.Cookie, error)

func (*ResponseHelper) Err added in v1.0.3

func (helper *ResponseHelper) Err() error

func (*ResponseHelper) FileBody

func (helper *ResponseHelper) FileBody(file io.Writer) error

func (*ResponseHelper) GobBody

func (helper *ResponseHelper) GobBody(body proto.Message) error

func (*ResponseHelper) Headers

func (helper *ResponseHelper) Headers() (http.Header, error)

func (*ResponseHelper) JSONBody

func (helper *ResponseHelper) JSONBody(body any) error

func (*ResponseHelper) ObjectBody

func (helper *ResponseHelper) ObjectBody(body any, unmarshal func([]byte, any) error) error

func (*ResponseHelper) ProtobufBody

func (helper *ResponseHelper) ProtobufBody(body proto.Message) error

func (*ResponseHelper) StatusCode

func (helper *ResponseHelper) StatusCode() (int, error)

func (*ResponseHelper) TextBody

func (helper *ResponseHelper) TextBody() (string, error)

func (*ResponseHelper) Trailer

func (helper *ResponseHelper) Trailer() (http.Header, error)

func (*ResponseHelper) XMLBody

func (helper *ResponseHelper) XMLBody(body any) error

type TransportBuilder

type TransportBuilder struct {
	// contains filtered or unexported fields
}

func (*TransportBuilder) Build

func (builder *TransportBuilder) Build() *http.Transport

func (*TransportBuilder) Dial

func (builder *TransportBuilder) Dial(dial func(ctx context.Context, network string, addr string) (net.Conn, error)) *TransportBuilder

func (*TransportBuilder) DialTLS

func (builder *TransportBuilder) DialTLS(dialTLS func(ctx context.Context, network string, addr string) (net.Conn, error)) *TransportBuilder

func (*TransportBuilder) DisableCompression

func (builder *TransportBuilder) DisableCompression(disable bool) *TransportBuilder

func (*TransportBuilder) DisableKeepAlives

func (builder *TransportBuilder) DisableKeepAlives(disable bool) *TransportBuilder

func (*TransportBuilder) ExpectContinueTimeout

func (builder *TransportBuilder) ExpectContinueTimeout(timeout time.Duration) *TransportBuilder

func (*TransportBuilder) ForceAttemptHTTP2

func (builder *TransportBuilder) ForceAttemptHTTP2(enable bool) *TransportBuilder

func (*TransportBuilder) GetProxyConnectHeader

func (builder *TransportBuilder) GetProxyConnectHeader(f func(ctx context.Context, proxyURL *url.URL, target string) (http.Header, error)) *TransportBuilder

func (*TransportBuilder) IdleConnTimeout

func (builder *TransportBuilder) IdleConnTimeout(timeout time.Duration) *TransportBuilder

func (*TransportBuilder) MaxConnsPerHost

func (builder *TransportBuilder) MaxConnsPerHost(n int) *TransportBuilder

func (*TransportBuilder) MaxIdleConns

func (builder *TransportBuilder) MaxIdleConns(n int) *TransportBuilder

func (*TransportBuilder) MaxIdleConnsPerHost

func (builder *TransportBuilder) MaxIdleConnsPerHost(n int) *TransportBuilder

func (*TransportBuilder) MaxResponseHeaderBytes

func (builder *TransportBuilder) MaxResponseHeaderBytes(n int64) *TransportBuilder

func (*TransportBuilder) Proxy

func (builder *TransportBuilder) Proxy(proxy func(*http.Request) (*url.URL, error)) *TransportBuilder

func (*TransportBuilder) ProxyConnectHeader

func (builder *TransportBuilder) ProxyConnectHeader(h http.Header) *TransportBuilder

func (*TransportBuilder) ReadBufferSize

func (builder *TransportBuilder) ReadBufferSize(n int) *TransportBuilder

func (*TransportBuilder) ResponseHeaderTimeout

func (builder *TransportBuilder) ResponseHeaderTimeout(timeout time.Duration) *TransportBuilder

func (*TransportBuilder) TLSConfig

func (builder *TransportBuilder) TLSConfig(tlsConfig *tls.Config) *TransportBuilder

func (*TransportBuilder) TLSHandshakeTimeout

func (builder *TransportBuilder) TLSHandshakeTimeout(timeout time.Duration) *TransportBuilder

func (*TransportBuilder) TLSNextProto

func (builder *TransportBuilder) TLSNextProto(f map[string]func(authority string, c *tls.Conn) http.RoundTripper) *TransportBuilder

func (*TransportBuilder) WriteBufferSize

func (builder *TransportBuilder) WriteBufferSize(n int) *TransportBuilder

Jump to

Keyboard shortcuts

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