Documentation ¶
Index ¶
- func EnsureHTTPTransport(r *Request) (typed *http.Transport, err error)
- func ErrIsTooManyRedirects(err error) bool
- func HostHasPort(s string) bool
- func RemoveHostEmptyPort(host string) string
- type Error
- type Option
- func OptBasicAuth(username, password string) Option
- func OptBody(body []byte) Option
- func OptBodyGob(obj interface{}) Option
- func OptBodyJSON(obj interface{}) Option
- func OptBodyReader(contents io.ReadCloser) Option
- func OptCheckRedirect(checkfn func(r *http.Request, via []*http.Request) error) Option
- func OptClientTimeout(d time.Duration) Option
- func OptCloser(closefn func() error) Option
- func OptContext(ctx context.Context) Option
- func OptCookie(cookie *http.Cookie) Option
- func OptCookieValue(key, value string) Option
- func OptDelete() Option
- func OptDialer(dialer net.Dialer) Option
- func OptDisableKeepAlives(disableKeepAlives bool) Option
- func OptErr(err error) Option
- func OptGet() Option
- func OptHeader(key, value string) Option
- func OptHeaderAdd(key, value string) Option
- func OptHeaderDel(key string) Option
- func OptHeaderSet(key, value string) Option
- func OptHeaders(headers http.Header) Option
- func OptHost(host string) Option
- func OptMaxRedirects(maxRedirects int) Option
- func OptMethod(method string) Option
- func OptOnRequest(listener func(*http.Request) error) Option
- func OptOnResponse(listener func(*http.Request, *http.Response, time.Time, error) error) Option
- func OptOptions() Option
- func OptPatch() Option
- func OptPath(path string) Option
- func OptPathf(format string, args ...any) Option
- func OptPost() Option
- func OptPut() Option
- func OptQuery(key, value string) Option
- func OptQueryAdd(key, value string) Option
- func OptQueryDel(key string) Option
- func OptQuerySet(key, value string) Option
- func OptRawQuery(rawQuery string) Option
- func OptRawQueryValues(q url.Values) Option
- func OptRequest(req *http.Request) Option
- func OptScheme(scheme string) Option
- func OptTLSClientCert(cert tls.Certificate) Option
- func OptTLSClientConfig(cfg *tls.Config) Option
- func OptTLSHandshakeTimeout(d time.Duration) Option
- func OptTLSInsecureSkipVerify(insecureSkipVerify bool) Option
- func OptTLSRootCAs(pool *x509.CertPool) Option
- func OptTransport(transport http.RoundTripper) Option
- func OptURL(u *url.URL) Option
- func OptURLParsed(rawURL string) Option
- func OptUserAgent(userAgent string) Option
- type Request
- func (r Request) Bytes() (contents []byte, res *http.Response, err error)
- func (r *Request) Close() error
- func (r Request) CopyTo(dst io.Writer) (count int64, err error)
- func (r Request) Discard() (res *http.Response, err error)
- func (r Request) Do() (*http.Response, error)
- func (r Request) Gob(dst interface{}) (res *http.Response, err error)
- func (r Request) JSON(dst interface{}) (res *http.Response, err error)
- func (r *Request) Method() string
- func (r *Request) URL() *url.URL
- func (r *Request) WithContext(ctx context.Context) *Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureHTTPTransport ¶
EnsureHTTPTransport ensures the http client's transport is set and that it is an *http.Transport.
It will return an error `ErrInvalidTransport` if it is set to something other than *http.Transport.
func ErrIsTooManyRedirects ¶
ErrIsTooManyRedirects returns if the error is too many redirects.
func HostHasPort ¶
HostHasPort returns true if a string is in the form "host:port", or "[ipv6::address]:port".
func RemoveHostEmptyPort ¶
RemoveHostEmptyPort strips the empty port in ":port" to "" as mandated by RFC 3986 Section 6.2.3.
Types ¶
type Error ¶
type Error string
Error is an error constant.
const ( // ErrRequestUnset is an error returned from options if they are called on a r2.Request that has not // been created by r2.New(), and as a result the underlying request is uninitialized. ErrRequestUnset Error = "r2; cannot modify request, underlying request unset. please use r2.New()" // ErrInvalidTransport is an error returned from options if they are called on a request that has had // the transport set to something other than an *http.Transport; this precludes using http.Transport // specific options like tls.Config mutators. ErrInvalidTransport Error = "r2; cannot modify transport, is not *http.Transport" // ErrNoContentJSON is returns from sending requests when a no-content status is returned. ErrNoContentJSON Error = "r2; server returned an http 204 for a request expecting json" // ErrNoContentGob is returns from sending requests when a no-content status is returned. ErrNoContentGob Error = "r2; server returned an http 204 for a request expecting a gob encoded response" // ErrInvalidMethod is an error that is returned from `r2.Request.Do()` if a method // is specified on the request that violates the valid charset for HTTP methods. ErrInvalidMethod Error = "r2; invalid http method" // ErrMismatchedPathParameters is an error that is returned from `OptParameterizedPath()` if // the parameterized path string has a different number of parameters than what was passed as // variadic arguments. ErrMismatchedPathParameters Error = "r2; route parameters provided don't match parameters needed in path" // ErrFormAndBodySet is an error where the caller has provided both a body and post form values. ErrFormAndBodySet Error = "r2; post form and body are both set" )
Error Constants
type Option ¶
Option is a modifier for a request.
func OptBasicAuth ¶
OptBasicAuth is an option that sets the http basic auth.
func OptBodyGob ¶
func OptBodyGob(obj interface{}) Option
OptBodyGob sets the post body on the request to a given value encoded with gob.
func OptBodyJSON ¶
func OptBodyJSON(obj interface{}) Option
OptBodyJSON sets the post body on the request to a given value encoded with json.
func OptBodyReader ¶
func OptBodyReader(contents io.ReadCloser) Option
OptBodyReader sets the post body on the request.
func OptCheckRedirect ¶
OptCheckRedirect sets the client check redirect function.
func OptClientTimeout ¶
OptClientTimeout sets the client timeout.
func OptCloser ¶
OptCloser sets the closer function on the request which is called once the request completes.
It is useful for closing underlying streams if they need to be re-used multiple times.
func OptCookieValue ¶
OptCookieValue adds a cookie value to a context.
func OptDisableKeepAlives ¶
OptDisableKeepAlives disables keep alives.
func OptErr ¶
OptErr sets the request error pre-emptively.
This should only be used for debugging or testing purposes as it will prevent requests from being sent.
func OptHeader ¶
OptHeader is an alias to `r2.OptHeaderSet` and sets a header on the request by key and value.
func OptHeaderAdd ¶
OptHeaderAdd adds a header value on a request.
func OptHeaderDel ¶
OptHeaderDel deletes a header by key on a request.
func OptHeaderSet ¶
OptHeaderSet sets a header value on a request.
func OptMaxRedirects ¶
OptMaxRedirects tells the http client to only follow a given number of redirects, overriding the standard library default of 10. Use the companion helper `ErrIsTooManyRedirects` to test if the returned error from a call indicates the redirect limit was reached.
func OptOnRequest ¶
OptOnRequest sets an on request listener.
func OptOnResponse ¶
OptOnResponse adds an on response listener. If an OnResponse listener has already been addded, it will be merged with the existing listener.
func OptQuery ¶
OptQuery is an alias to `r2.OptQuerySet` and sets a query string value on the request url by key and value.
func OptQueryAdd ¶
OptQueryAdd adds a header value on a request.
func OptQueryDel ¶
OptQueryDel deletes a header by key on a request.
func OptQuerySet ¶
OptQuerySet sets a header value on a request.
func OptRawQuery ¶
OptRawQuery sets the request url query string.
func OptRawQueryValues ¶
OptRawQueryValues sets the request url query string.
func OptRequest ¶
OptRequest sets the raw underlying request.
This should only be used in testing or debugging situations.
func OptTLSClientCert ¶
func OptTLSClientCert(cert tls.Certificate) Option
OptTLSClientCert adds a client certificate to the request.
func OptTLSClientConfig ¶
OptTLSClientConfig sets the tls config for the request. It will create a client, and a transport if unset.
func OptTLSHandshakeTimeout ¶
OptTLSHandshakeTimeout sets the client transport TLSHandshakeTimeout.
func OptTLSInsecureSkipVerify ¶
OptTLSInsecureSkipVerify sets if we should skip verification.
func OptTLSRootCAs ¶
OptTLSRootCAs sets the client tls root ca pool.
func OptTransport ¶
func OptTransport(transport http.RoundTripper) Option
OptTransport sets the client transport for a request.
func OptURLParsed ¶
OptURLParsed sets the url of a request by parsing the given raw url.
func OptUserAgent ¶
OptUserAgent sets the user agent header on a request. It will initialize the request headers map if it's unset. It will overwrite any existing user agent header.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is a combination of the http.Request options and the underlying client.
func (Request) Bytes ¶
Bytes reads the response and returns it as a byte array, along with the response metadata..
func (Request) Discard ¶
Discard reads the response fully and discards all data it reads, and returns the response metadata.
func (Request) Gob ¶
Gob reads the response as gob into a given object and returns the response metadata.
Source Files ¶
- ensure_http_transport.go
- errors.go
- opt_basic_auth.go
- opt_body.go
- opt_check_redirect.go
- opt_client_timeout.go
- opt_closer.go
- opt_context.go
- opt_cookie.go
- opt_dialer.go
- opt_disable_keep_alives.go
- opt_err.go
- opt_headers.go
- opt_method.go
- opt_on_request.go
- opt_on_response.go
- opt_query.go
- opt_request.go
- opt_tls.go
- opt_transport.go
- opt_url.go
- opt_user_agent.go
- option.go
- remove_host_empty_port.go
- request.go