HTTP Client

Tags: applications

Added in version 0.5.

Changed in version 0.10: Caching functionality was extracted to the separate http_cache application.

The harp_apps.http_client application implements the core HTTP client features for making HTTP requests to external services.

The application defines a coherent set of services that are used to interact with external HTTP services, allowing other mechanisms to hook into the request/response lifecycle (cache, rules, …).

For HTTP caching functionality, see the http_cache application, which provides RFC 9111-compliant caching using Hishel 1.0.

Overview

The HTTP client provides efficient and configurable HTTP request handling for making requests to external services. It is designed to be integrated seamlessly into the harp framework and supports extensibility through transport wrappers.

Features

  • Async HTTP Client: Built on httpx for high-performance async requests

  • Configurable Timeouts: Allows setting custom timeout values for requests

  • Transport Layer: Flexible transport architecture supporting middleware and extensions

  • Event System: Hooks for request/response lifecycle events

  • Extensible: Supports integration with caching, rules, and other applications

Loading

The HTTP client application is loaded by default when using the harp-proxy start command.

Configuration

Below is an example configuration for the HTTP client:

http_client:
  # Timeout error will occur if the HTTP client does not receive a response within 10
  # seconds (default is 30 seconds).
  timeout: 10.0

  # Transport configuration (optional)
  transport:
    # You can customize the default transport implementation. The values shown are the
    # defaults, and you only need to set them if you want to provide different values.
    type: httpx.AsyncHTTPTransport
    retries: 0
    verify: true
    http1: true
    http2: false

Configuration options:

  • timeout: Specifies the request timeout duration in seconds (default: 30.0)

  • transport: The base HTTP transport implementation (default: httpx.AsyncHTTPTransport)

  • proxy_transport: The proxy transport wrapper (default: AsyncFilterableTransport)

For caching configuration, see the http_cache application documentation.

Internal Implementation

The internal implementation leverages the following classes:

For cache implementation details, see the http_cache application.

Full example

http_client:
  # HTTP timeout (default to `harp.settings.DEFAULT_TIMEOUT`)
  timeout: 10.0

  # Customize the httpx transport layer (optional)
  transport:
    # This is the default, only set if you want to use a custom transport. Most users don't need to set this.
    type: httpx.AsyncHTTPTransport

  # Proxy transport layer (optional) - wraps the transport for filtering and middleware
  proxy_transport:
    # This is the default, only set if you want to use a custom proxy transport.
    type: harp_apps.http_client.transports.AsyncFilterableTransport

# Cache configuration has been moved to the http_cache application.
# See the http_cache application documentation for cache configuration options.
# Example:
#
# http_cache:
#   enabled: true
#   policy:
#     type: hishel.SpecificationPolicy
#     arguments:
#       cache_options:
#         shared: true
#         supported_methods: [GET, HEAD]
#         allow_stale: false