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
has_error: bool

False if the response was successfully sent to the client, True if an error was encountered.

error_message: str

When has_error is True, this will contain the error message. Otherwise, it will be an empty string.

alias of Callable[[bool, str], None]

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 not None) with the response object. When on_success_fn is None, a tuple containing the request session and the response object is returned, otherwise a tuple containing the request session and the return value of on_success_fn is returned.

If on_success_fn raises an exception, it is treated as a failure and the request is retried.

Previous morpheus.utils.file_utils
Next morpheus.utils.http_utils.HTTPMethod
© Copyright 2024, NVIDIA. Last updated on Apr 25, 2024.