morpheus.utils.http_utils
HTTP utilities
Functions
prepare_url (url) |
Verifies that url contains a protocol scheme and a host and returns the url. |
request_with_retry (request_kwargs[, ...]) |
Wrapper around requests.request that retries on failure. |
Classes
HTTPMethod (value) |
Not a complete list of HTTP methods, just the ones we use. |
HttpParseResponse (status_code, content_type, ...) |
A tuple consisting of the HTTP status code, mime type to be used for the Content-Type header, the body of the response and an optional callback function to be invoked once the response is completed. |
MimeTypes (value) |
Not a complete list of mime types, just the ones we use. |
- HttpOnCompleteCallbackFn[source]
Optional callback function invoked by
morpheus.common.HttpServer
once a response is completed, either successfully or encountered a failure.- Parameters
- prepare_url(url)[source]
Verifies that
url
contains a protocol scheme and a host and returns the url. If no protocol scheme is provided,http
is used.
- request_with_retry(request_kwargs, requests_session=None, max_retries=10, sleep_time=0.1, accept_status_codes=(<HTTPStatus.OK: 200>, ), respect_retry_after_header=True, on_success_fn=None)[source]
Wrapper around
requests.request
that retries on failure.This code is a work-around for an issue (https://github.com/urllib3/urllib3/issues/2751), in urllib3’s Retry class and should be removed once it is resolved.
Upon successfull completion, the
on_success_fn
is called (if notNone
) with the response object. Whenon_success_fn
isNone
, a tuple containing the request session and the response object is returned, otherwise a tuple containing the request session and the return value ofon_success_fn
is returned.If
on_success_fn
raises an exception, it is treated as a failure and the request is retried.