Request Headers#

The request headers plugin hooks allows plugin authors to add custom HTTP headers to HTTP requests within conda. This works by inserting these headers while preparing the requests.PreparedRequest object when calling requests.Session.request.

There are two hooks available for this purpose:

  1. conda_session_headers(): This hook is used to define the custom headers that will be submitted with all HTTP requests (or a subset of hosts)

  2. conda_request_headers(): This hook is used to define the custom headers that will be submitted with a specific HTTP request.

Warning

While the second hook (conda_request_headers()) can also create session headers, it is recommended to use the first hook (conda_session_headers()) for improved caching performance.

conda_request_headers(host: str, path: str)#

Register new HTTP request headers

The example below defines how to add HTTP headers for all requests with the hostname of example.com and a path/to/endpoint.json path.

Example:

from conda import plugins

HOSTS = {"example.com", "sub.example.com"}
ENDPOINT = "/path/to/endpoint.json"


@plugins.hookimpl
def conda_request_headers(host: str, path: str):
    if host in HOSTS and path == ENDPOINT:
        yield plugins.CondaRequestHeader(
            name="Example-Header",
            value="example",
        )
conda_session_headers(host: str)#

Register new HTTP request headers

The example below defines how to add HTTP headers for all requests with the hostname of example.com.

Example:

from conda import plugins

HOSTS = {"example.com", "sub.example.com"}


@plugins.hookimpl
def conda_session_headers(host: str):
    if host in HOSTS:
        yield plugins.CondaRequestHeader(
            name="Example-Header",
            value="example",
        )

Both hook use the CondaRequestHeader class to define headers:

class CondaRequestHeader#

Define vendor specific headers to include HTTP requests

For details on how this is used, see conda_request_headers() and conda_session_headers().

Parameters:
  • name -- name of the header used in the HTTP request

  • value -- value of the header used in the HTTP request

name#
value#