httputil

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package httputil provides shared HTTP infrastructure for proxy support, custom TLS, and header propagation across all MCP servers.

All outbound HTTP clients (GitHub API, LLM endpoints) use this package so that proxy, CA certificate, and header-forwarding settings apply uniformly.

Index

Constants

View Source
const DialTimeout = 30 * time.Second

DialTimeout is a sensible default for custom transports.

Variables

This section is empty.

Functions

func DefaultClient

func DefaultClient(timeout time.Duration) *http.Client

DefaultClient creates a minimal client that still honors env-based proxy and propagates context headers. Use when no explicit ProxyConfig is needed.

func HeaderCaptureMiddleware

func HeaderCaptureMiddleware(allowList []string, next http.Handler) http.Handler

HeaderCaptureMiddleware returns an http.Handler that captures selected headers from inbound requests into the request context so that downstream MCP tool handlers can propagate them to outbound calls.

When allowList is empty, all headers are captured.

func HeadersFromContext

func HeadersFromContext(ctx context.Context) http.Header

HeadersFromContext retrieves previously stored headers. Returns nil if none.

func NewClient

func NewClient(cfg ProxyConfig, timeout time.Duration) (*http.Client, error)

NewClient creates an *http.Client with proxy/TLS settings and the given timeout. Outbound requests automatically propagate context headers (see WithHeaders).

func NewTransport

func NewTransport(cfg ProxyConfig) (*http.Transport, error)

NewTransport creates an *http.Transport configured with proxy, TLS, and header-propagation settings. The returned transport automatically forwards headers stored in the request context (see WithHeaders / HeadersFromContext).

func WithHeaders

func WithHeaders(ctx context.Context, h http.Header) context.Context

WithHeaders stores HTTP headers in context for downstream propagation.

Types

type ProxyConfig

type ProxyConfig struct {
	// ProxyURL overrides the proxy. When empty, Go's default behavior applies:
	// HTTP_PROXY / HTTPS_PROXY / NO_PROXY environment variables are honored.
	ProxyURL string `yaml:"proxy_url"`

	// CACertFile is a PEM-encoded CA bundle appended to the system pool.
	// Typically used for corporate TLS-intercepting proxies.
	CACertFile string `yaml:"ca_cert"`

	// TLSInsecureSkipVerify disables certificate verification. Use for testing only.
	TLSInsecureSkipVerify bool `yaml:"tls_insecure_skip_verify"`

	// HeaderPassthrough lists HTTP header names that should be forwarded from
	// incoming MCP requests to outbound calls (GitHub, LLM). Case-insensitive.
	// When empty, no headers are forwarded.
	HeaderPassthrough []string `yaml:"header_passthrough"`
}

ProxyConfig holds network settings shared across all HTTP clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL