Documentation
¶
Overview ¶
Package http defines higher level helpers for the net/http package
Index ¶
- Variables
- func ConstructURL(u *url.URL, params URLParameters) (string, error)
- func EnsureValidURL(s string, trailing bool) (string, error)
- func JoinURLPath(u string, p string) (string, error)
- func RegisterAgent(client string, verApp string)
- type Client
- type OptionalParams
- type StatusError
- type TimeoutError
- type URLParameters
Constants ¶
This section is empty.
Variables ¶
var DefaultTransport = tls13Transport()
DefaultTransport is the default HTTP transport to use by default it is a transport that only allows TLS 1.3
var UserAgent string
UserAgent is the user agent that is used for requests
Functions ¶
func ConstructURL ¶
func ConstructURL(u *url.URL, params URLParameters) (string, error)
ConstructURL creates a URL with the included parameters.
func EnsureValidURL ¶
EnsureValidURL ensures that the input URL is valid to be used internally It does the following - Sets the scheme to https if none is given - It 'cleans' up the path using path.Clean - It makes sure that the URL ends with a / It returns an error if the URL cannot be parsed.
func JoinURLPath ¶
JoinURLPath joins url's path, in go 1.19 we can use url.JoinPath
func RegisterAgent ¶
RegisterAgent registers the user agent for client and version
Types ¶
type Client ¶
type Client struct {
// Client is the HTTP Client that sends the request
Client *http.Client
// ReadLimit denotes the maximum amount of bytes that are read in HTTP responses
// This is used to prevent servers from sending huge amounts of data
// A limit of 16MB, although maybe much larger than needed, ensures that we do not run into problems
ReadLimit int64
// Timeout denotes the default timeout for each request
Timeout time.Duration
}
Client is a wrapper around http.Client with some convenience features - A default timeout of 5 seconds - A read limiter to prevent servers from sending large amounts of data - Checking on http code with custom errors
type OptionalParams ¶
type OptionalParams struct {
Headers http.Header
URLParameters URLParameters
Body url.Values
Timeout time.Duration
}
OptionalParams is a structure that defines the optional parameters that are given when making a HTTP call.
type StatusError ¶
StatusError indicates that we have received a HTTP status error.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
Error returns the StatusError as an error string.
type TimeoutError ¶
TimeoutError indicates that we have gotten a timeout
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
Error returns the TimeoutError as an error string.
type URLParameters ¶
URLParameters is a type used for the parameters in the URL.