WeaviateEx.Config.Proxy (WeaviateEx v0.7.4)

View Source

Proxy configuration for HTTP, HTTPS, and gRPC connections.

This module provides proxy support for Weaviate client connections, reading from environment variables or explicit configuration.

Environment Variables

The following environment variables are read (case-insensitive):

  • HTTP_PROXY / http_proxy - HTTP proxy URL
  • HTTPS_PROXY / https_proxy - HTTPS proxy URL
  • GRPC_PROXY / grpc_proxy - gRPC proxy URL

Uppercase variables take precedence over lowercase.

Examples

# From environment variables
proxy = Proxy.from_env()

# Explicit configuration
proxy = Proxy.new(
  http: "http://proxy.example.com:8080",
  https: "https://proxy.example.com:8443",
  grpc: "grpc://proxy.example.com:50051"
)

# Check if proxy is configured
Proxy.configured?(proxy)
# => true

# Get proxy for a specific URL
Proxy.http_proxy_for(proxy, "https://weaviate.example.com")
# => "https://proxy.example.com:8443"

# Get Finch HTTP client options
Proxy.to_finch_opts(proxy)
# => [proxy: {:https, "proxy.example.com", 8443, []}]

# Get gRPC channel options
Proxy.to_grpc_opts(proxy)
# => [http_proxy: "grpc://proxy.example.com:50051"]

Summary

Functions

Check if any proxy is configured.

Create proxy configuration from environment variables.

Get the appropriate HTTP proxy for a given URL.

Create a new proxy configuration from explicit options.

Convert proxy configuration to Finch HTTP client options.

Convert proxy configuration to gRPC channel options.

Types

t()

@type t() :: %WeaviateEx.Config.Proxy{
  grpc: String.t() | nil,
  http: String.t() | nil,
  https: String.t() | nil
}

Functions

configured?(proxy)

@spec configured?(t()) :: boolean()

Check if any proxy is configured.

Examples

proxy = Proxy.new()
Proxy.configured?(proxy)
# => false

proxy = Proxy.new(http: "http://proxy:8080")
Proxy.configured?(proxy)
# => true

from_env()

@spec from_env() :: t()

Create proxy configuration from environment variables.

Reads from the following environment variables (case-insensitive):

  • HTTP_PROXY / http_proxy
  • HTTPS_PROXY / https_proxy
  • GRPC_PROXY / grpc_proxy

Uppercase variables take precedence over lowercase.

Examples

# With HTTP_PROXY=http://proxy:8080 set
proxy = Proxy.from_env()
proxy.http
# => "http://proxy:8080"

http_proxy_for(proxy, url)

@spec http_proxy_for(t(), String.t()) :: String.t() | nil

Get the appropriate HTTP proxy for a given URL.

Returns the HTTPS proxy for https:// URLs and HTTP proxy for http:// URLs. Falls back to HTTP proxy if HTTPS proxy is not configured.

Examples

proxy = Proxy.new(http: "http://proxy:8080", https: "https://proxy:8443")

Proxy.http_proxy_for(proxy, "http://api.example.com")
# => "http://proxy:8080"

Proxy.http_proxy_for(proxy, "https://api.example.com")
# => "https://proxy:8443"

new(opts \\ [])

@spec new(keyword()) :: t()

Create a new proxy configuration from explicit options.

Options

Examples

Proxy.new(
  http: "http://proxy.example.com:8080",
  https: "https://proxy.example.com:8443"
)

to_finch_opts(proxy)

@spec to_finch_opts(t()) :: keyword()

Convert proxy configuration to Finch HTTP client options.

Returns options suitable for passing to Finch.build/3.

Examples

proxy = Proxy.new(https: "https://proxy.example.com:8443")
Proxy.to_finch_opts(proxy)
# => [proxy: {:https, "proxy.example.com", 8443, []}]

to_grpc_opts(proxy)

@spec to_grpc_opts(t()) :: keyword()

Convert proxy configuration to gRPC channel options.

Returns options suitable for passing to GRPC.Stub.connect/2.

Examples

proxy = Proxy.new(grpc: "http://grpc-proxy.example.com:8080")
Proxy.to_grpc_opts(proxy)
# => [http_proxy: "http://grpc-proxy.example.com:8080"]