Documentation ¶
Overview ¶
Package http handles interacting with HTTP clients and servers.
This package allows you to make HTTP requests through an HTTP proxy even those using an untrusted certificate (eg: signed by an internal CA).
Note that only HTTP Basic authentication is supported for proxy communication at this time.
Index ¶
- Constants
- type Client
- func (c *Client) Delete(url string, headers map[string]string, body []byte, ctx context.Context) (*http.Response, []byte, error)
- func (c *Client) Get(url string, headers map[string]string, ctx context.Context) (*http.Response, []byte, error)
- func (c *Client) NewRequest(method, url string, body io.Reader, ctx context.Context) (*http.Client, *http.Request, error)
- func (c *Client) Options(url string, headers map[string]string, ctx context.Context) (*http.Response, []byte, error)
- func (c *Client) Patch(url string, headers map[string]string, body []byte, ctx context.Context) (*http.Response, []byte, error)
- func (c *Client) Post(url string, headers map[string]string, body []byte, ctx context.Context) (*http.Response, []byte, error)
- func (c *Client) Put(url string, headers map[string]string, body []byte, ctx context.Context) (*http.Response, []byte, error)
- type ErrCreateRequestFailure
- type ErrDoRequestFailure
- type ErrParseUrlFailure
- type ErrProxyFailure
- type ErrReadResponseFailure
- type ErrStatusCodeNotOK
- type ProxyConfig
Constants ¶
const ( ErrParseUrlFailureCode = 2251 ErrProxyFailureCode = 2252 ErrCreateRequestFailureCode = 2253 ErrDoRequestFailureCode = 2254 ErrReadResponseFailureCode = 2255 )
Object error codes (2251-2500)
const ( // StatusPanicRecovery indicates that a panic was detected in code but automatic recovery prevented the // application from crashing. StatusPanicRecovery = 599 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // ClientCertificates is a list of certificates to pass for client authentication. ClientCertificates []tls.Certificate // DisableSSLVerification disables HTTPS certificate verification when connecting to a server. You should // only do this if you are *really* sure. Otherwise, add the server's certificate to the RootCertificates // pool. DisableSSLVerification bool // RootCertificates is a pool of root CA certificates to trust. RootCertificates *crypto.CertificatePool // contains filtered or unexported fields }
Client represents an HTTP client.
func NewClient ¶
func NewClient(proxyConfig ProxyConfig) *Client
NewClient returns a new HTTP client object.
func (*Client) Delete ¶
func (c *Client) Delete(url string, headers map[string]string, body []byte, ctx context.Context) ( *http.Response, []byte, error)
Delete performs a DELETE request for the given URL and returns the raw body byte array.
The following errors are returned by this function: ErrCreateRequestFailure, ErrDoRequestFailure, ErrReadResponseFailure, ErrStatusCodeNotOK
func (*Client) Get ¶
func (c *Client) Get(url string, headers map[string]string, ctx context.Context) ( *http.Response, []byte, error)
Get performs a GET request for the given URL and returns the raw body byte array.
The following errors are returned by this function: ErrCreateRequestFailure, ErrDoRequestFailure, ErrReadResponseFailure, ErrStatusCodeNotOK
func (*Client) NewRequest ¶
func (c *Client) NewRequest(method, url string, body io.Reader, ctx context.Context) ( *http.Client, *http.Request, error)
NewRequest creates a new HTTP request object using any configured proxy information.
Note that only HTTP Basic authentication is supported for proxied requests.
The following errors are returned by this function: ErrParseUrlFailure, ErrProxyFailure, ErrCreateRequestFailure
func (*Client) Options ¶
func (c *Client) Options(url string, headers map[string]string, ctx context.Context) ( *http.Response, []byte, error)
Options performs an OPTIONS request for the given URL and returns the raw body byte array.
The following errors are returned by this function: ErrCreateRequestFailure, ErrDoRequestFailure, ErrReadResponseFailure, ErrStatusCodeNotOK
func (*Client) Patch ¶
func (c *Client) Patch(url string, headers map[string]string, body []byte, ctx context.Context) ( *http.Response, []byte, error)
Patch performs a PATCH request for the given URL and returns the raw body byte array.
The following errors are returned by this function: ErrCreateRequestFailure, ErrDoRequestFailure, ErrReadResponseFailure, ErrStatusCodeNotOK
func (*Client) Post ¶
func (c *Client) Post(url string, headers map[string]string, body []byte, ctx context.Context) ( *http.Response, []byte, error)
Post performs a POST request for the given URL and returns the raw body byte array.
The following errors are returned by this function: ErrCreateRequestFailure, ErrDoRequestFailure, ErrReadResponseFailure, ErrStatusCodeNotOK
func (*Client) Put ¶
func (c *Client) Put(url string, headers map[string]string, body []byte, ctx context.Context) ( *http.Response, []byte, error)
Put performs a PUT request for the given URL and returns the raw body byte array.
The following errors are returned by this function: ErrCreateRequestFailure, ErrDoRequestFailure, ErrReadResponseFailure, ErrStatusCodeNotOK
type ErrCreateRequestFailure ¶ added in v0.1.5
ErrCreateRequestFailure occurs when there is an error creating a new HTTP request.
func (*ErrCreateRequestFailure) Code ¶ added in v0.1.5
func (e *ErrCreateRequestFailure) Code() int
Code returns the corresponding error code.
func (*ErrCreateRequestFailure) Error ¶ added in v0.1.5
func (e *ErrCreateRequestFailure) Error() string
Error returns the string version of the error.
func (*ErrCreateRequestFailure) InternalError ¶ added in v0.1.9
func (e *ErrCreateRequestFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrDoRequestFailure ¶ added in v0.1.5
ErrDoRequestFailure occurs when there is an error executing a request.
func (*ErrDoRequestFailure) Code ¶ added in v0.1.5
func (e *ErrDoRequestFailure) Code() int
Code returns the corresponding error code.
func (*ErrDoRequestFailure) Error ¶ added in v0.1.5
func (e *ErrDoRequestFailure) Error() string
Error returns the string version of the error.
func (*ErrDoRequestFailure) InternalError ¶ added in v0.1.9
func (e *ErrDoRequestFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrParseUrlFailure ¶ added in v0.1.5
ErrParseUrlFailure occurs when there is an error parsing a URL.
func (*ErrParseUrlFailure) Code ¶ added in v0.1.5
func (e *ErrParseUrlFailure) Code() int
Code returns the corresponding error code.
func (*ErrParseUrlFailure) Error ¶ added in v0.1.5
func (e *ErrParseUrlFailure) Error() string
Error returns the string version of the error.
func (*ErrParseUrlFailure) InternalError ¶ added in v0.1.9
func (e *ErrParseUrlFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrProxyFailure ¶ added in v0.1.5
ErrorProxyFailure occurs when there is an error retrieving a proxy URL.
func (*ErrProxyFailure) Code ¶ added in v0.1.5
func (e *ErrProxyFailure) Code() int
Code returns the corresponding error code.
func (*ErrProxyFailure) Error ¶ added in v0.1.5
func (e *ErrProxyFailure) Error() string
Error returns the string version of the error.
func (*ErrProxyFailure) InternalError ¶ added in v0.1.9
func (e *ErrProxyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrReadResponseFailure ¶ added in v0.1.5
type ErrReadResponseFailure struct {
Err error
}
ErrReadResponseFailure occurs when there is an error reading a response body.
func (*ErrReadResponseFailure) Code ¶ added in v0.1.5
func (e *ErrReadResponseFailure) Code() int
Code returns the corresponding error code.
func (*ErrReadResponseFailure) Error ¶ added in v0.1.5
func (e *ErrReadResponseFailure) Error() string
Error returns the string version of the error.
func (*ErrReadResponseFailure) InternalError ¶ added in v0.1.9
func (e *ErrReadResponseFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrStatusCodeNotOK ¶ added in v0.1.5
type ErrStatusCodeNotOK struct {
StatusCode int
}
ErrStatusCodeNotOK occurs when an HTTP status code of 400 or greater is returned.
func (*ErrStatusCodeNotOK) Code ¶ added in v0.1.5
func (e *ErrStatusCodeNotOK) Code() int
Code returns the corresponding error code.
func (*ErrStatusCodeNotOK) Error ¶ added in v0.1.5
func (e *ErrStatusCodeNotOK) Error() string
Error returns the string version of the error.
func (*ErrStatusCodeNotOK) InternalError ¶ added in v0.1.9
func (e *ErrStatusCodeNotOK) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ProxyConfig ¶
type ProxyConfig struct { httpproxy.Config // HTTPProxyUser is the username for proxy authentication for HTTP URLs. HTTPProxyUser string // HTTPProxyPass is the password for proxy authentication for HTTP URLs. HTTPProxyPass string // HTTPSProxyUser is the username for proxy authentication for HTTPS URLs. HTTPSProxyUser string // HTTPSProxyPass is the password for proxy authentication for HTTPS URLs. HTTPSProxyPass string }
ProxyConfig holds the full configuration for proxy settings used by HTTP clients.