harp_apps.proxy.controllers

Inheritance diagram of harp_apps.proxy.controllers

class AbstractHttpProxyController[source]

Bases: ABC

__init__(remote, *, http_client, dispatcher=None, name=None, logging=True)[source]
Parameters:
async adispatch(event_id, event=None)[source]

Shortcut method to dispatch an event using the controller’s dispatcher, if there is one.

Returns:

IEvent or None

debug(message, *args, **kwargs)[source]
info(message, *args, **kwargs)[source]
initialize()[source]
warning(message, *args, **kwargs)[source]
property dispatcher

Read-only reference to the event dispatcher.

name: str | None = None

Controller name, also refered as endpoint name (for example in Transaction).

remote: Remote

Base URL to proxy requests to.

class HttpProxyController[source]

Bases: AbstractHttpProxyController

Adds the transaction logic and actual implementation to the abstract controller.

async end_transaction(transaction, response)[source]

Finalize the transaction and dispatch relevant events.

Parameters:
Returns:

The final HttpResponse object.

Return type:

HttpResponse

async failure(transaction, base_url, response=None)[source]

Handle a failure scenario by updating the transaction status and creating an appropriate HttpError response.

Parameters:
  • transaction (Transaction) – The current transaction object.

  • base_url (str | None) – The base URL of the remote server.

  • response (Exception | BaseHttpMessage | None) – The response or exception that caused the failure.

Returns:

The final HttpResponse object.

async filter_request(context)[source]
Parameters:

context (ProxyFilterEvent)

Return type:

ProxyFilterEvent | HttpResponse | dict | None

async filter_response(context)[source]
Parameters:

context (ProxyFilterEvent)

Return type:

ProxyFilterEvent | HttpResponse | dict | None

async forward(transaction, context, base_url, full_url)[source]

Forward the request to the remote server.

Parameters:
  • transaction (Transaction) – The current transaction object.

  • context (ProxyFilterEvent) – The proxy filter event context.

  • base_url (str) – The base URL of the remote server.

  • full_url (str) – The full URL to which the request is forwarded.

Returns:

The HTTP response received from the remote server.

Return type:

HttpResponse