Skip to content

HTTP Transport Class

Renato Byrro edited this page Feb 16, 2021 · 3 revisions

The http_logging.AsyncHttpTransport Class inherits from logstash_async.transport.HttpTransport and provides basic functionality to generalize HTTP connections for any backend (apart from LogStash)[about LogStash inheritance].

In general, you will not need to instantiate your own AsyncHttpTransport objects, since AsyncHttpHandler already does that for you when instantiated[AsyncHttpHandler.transport].

Three main reasons to create our own HTTP transport class:

  1. Extend the send method and remove the auth argument to requests to host (particular to how LogStash works, but we wanted an approach agnostic to the backend stack)
  2. Enable adding a path[AsyncHttpHandler.path] to the URL, making it more flexible in connecting to virtually any HTTP API out there
  3. Allow setting custom HTTP headers in requests to host[custom headers]

Usage

The AsyncHttpTransport is used as an argument to the AsyncHttpHandler Class[AsyncHttpHandler]:

from http_logging import AsyncHttpHandler, AsyncHttpTransport

host = 'my-domain.com'

handler = AsyncHttpHandler(
    host=host,
    transport=AsyncHttpTransport(
        host=host,
    )
)

Footnotes

[about LogStash inheritance] Read more about why we inherit from Python LogStash Async in our documentation

[AsyncHttpHandler.transport] Please refer to the AsyncHttpHandler.transport API reference.

[AsyncHttpHandler.path] Please refer to the AsyncHttpHandler.path attribute API reference.

[custom headers] Please refer to Adding custom HTTP headers to requests in the documentation.

[AsyncHttpHandler] Please refer to the Handler Class documentation.

Clone this wiki locally