Documentation ¶
Overview ¶
Package lhttp implements HTTP client helper code (JSON, automatic retries, authentication, etc).
'l' stands for luci.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsHTTPError ¶
func IsLocalHost ¶
IsLocalHost returns true if hostport is local.
func NewRequest ¶
func NewRequest(ctx context.Context, c *http.Client, rFn retry.Factory, rgen RequestGen, handler Handler, errorHandler ErrorHandler) func() (int, error)
NewRequest returns a retriable request.
The handler func is responsible for closing the response Body before returning. It should return retry.Error in case of retriable error, for example if a TCP connection is terminated while receiving the content.
If rFn is nil, NewRequest will use a default exponential backoff strategy only for transient errors.
If errorHandler is nil, the default error handler will drain and close the response body.
func ParseHostURL ¶
ParseHostURL ensures that the URL has a valid scheme and that it uses `http://` only when the host is a localhost server.
If no scheme is specified, the scheme defaults to `https://`.
If the URL has a path component, it is silently stripped.
Types ¶
type ErrorHandler ¶
ErrorHandler is called once or multiple times for each HTTP request that is tried. It is called when any non-200 response code is received, or if some other network error occurs. resp may be nil if a network error occurred before the response was received. The ErrorHandler must close the provided resp, if any. Return the same error again to continue retry behaviour, or nil to pretend this error was a success.
type RequestGen ¶
RequestGen is a generator function to create a new request. It may be called multiple times if an operation needs to be retried. The HTTP server is responsible for closing the Request body, as per http.Request Body method documentation.