typesense-python icon indicating copy to clipboard operation
typesense-python copied to clipboard

feat: Add support for additional headers in API requests

Open tharropoulos opened this issue 1 year ago • 0 comments

What is this?

This pull request introduces the ability to include custom headers in API requests to Typesense. This enhancement provides greater flexibility for users who need to send specific headers with their requests, such as for authentication or custom metadata. This tries to address the feature request discussed on #54

Changes

Added Features:

  1. New configuration option in configuration.py:
    • additional_headers: A dictionary to specify custom headers to be included in all API requests.

Code Changes:

  1. In src/typesense/configuration.py:

    • Added additional_headers to the ConfigDict type definition.
    • Updated the Configuration class to include an additional_headers attribute, initialized from the config dictionary.
  2. In src/typesense/request_handler.py:

    • Modified the RequestHandler._execute_request method to include the additional_headers from the configuration in all outgoing requests.
  3. In tests/api_call_test.py:

    • Added a new test case test_additional_headers to verify that additional headers from the configuration are correctly included in API requests.
  4. In tests/configuration_test.py:

    • Updated the test_configuration_explicit test to include additional_headers in the configuration and expected output.

Documentation Updates:

  1. In src/typesense/configuration.py:
    • Added documentation for the new additional_headers configuration option in the ConfigDict class docstring.

##PR Checklist

tharropoulos avatar Sep 16 '24 14:09 tharropoulos