httputil

package
v2.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httputil provides shared HTTP client construction utilities for the PromptKit project. It centralizes timeout defaults and client creation so that every module uses consistent configuration.

Index

Constants

View Source
const (
	// DefaultProviderTimeout is the HTTP timeout for LLM provider calls
	// (e.g. OpenAI, Claude, Gemini). Provider requests can involve large
	// payloads and long inference times, so they use a longer timeout.
	DefaultProviderTimeout = 60 * time.Second

	// DefaultToolTimeout is the HTTP timeout for tool / webhook calls
	// made by the SDK HTTP executor. These are typically shorter-lived
	// API requests.
	DefaultToolTimeout = 30 * time.Second

	// DefaultStreamingTimeout is the HTTP timeout for streaming provider
	// responses (e.g. SSE streams). Streaming connections stay open much
	// longer than regular request/response cycles.
	DefaultStreamingTimeout = 300 * time.Second
)

Standard timeout defaults used across the project.

Variables

View Source
var ErrNonPublicDestination = errors.New("destination is not a public address")

ErrNonPublicDestination is returned when a guarded client is asked to connect to an address that is not on the public internet.

View Source
var WellKnownCredentialHeaders = []string{
	"Authorization",
	"Proxy-Authorization",
	"X-Api-Key",
	"Api-Key",
	"X-Goog-Api-Key",
	"Xi-Api-Key",
	"X-Amz-Date",
	"X-Amz-Security-Token",
	"X-Amz-Content-Sha256",
}

WellKnownCredentialHeaders are the request headers that carry a credential for the providers PromptKit ships: bearer and API-key headers, and the headers a SigV4 signature sets. CredentialRedirectPolicy drops them on every redirect off the origin, whatever credential set them.

Functions

func CredentialRedirectPolicy added in v2.17.0

func CredentialRedirectPolicy(
	names func() []string, next func(*http.Request, []*http.Request) error,
) func(*http.Request, []*http.Request) error

CredentialRedirectPolicy returns an http.Client CheckRedirect function that keeps a credential on its origin. On a redirect to a scheme or host other than the first request's (see SameOriginAsFirstHop), it deletes every header in WellKnownCredentialHeaders and in names() from the hop before it is sent. http.Client copies every header but Authorization and cookies to a redirect hop, and keeps Authorization on a subdomain, so without this an X-API-Key or a SigV4 security token follows a redirect to any host.

names is called only for a redirect off the origin, so a credential that must look itself up to name its headers does so only then. A nil names strips only the well-known headers.

After stripping it applies next, or http.Client's default policy (stop after 10 redirects) when next is nil.

func IsPublicAddress added in v2.13.0

func IsPublicAddress(ip netip.Addr) bool

IsPublicAddress reports whether ip is an ordinary public address: not loopback, private, link-local (which is where cloud metadata services live), multicast, unspecified or otherwise reserved.

func NewHTTPClient

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

NewHTTPClient returns an *http.Client configured with the given timeout, a TLS 1.2 minimum, and connection pool limits. Pass one of the Default*Timeout constants, or a custom duration.

func NewPublicHTTPClient added in v2.13.0

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

NewPublicHTTPClient returns an HTTP client that connects only to public addresses. Use it to fetch a URL that came from a model, a remote client or any other input the host does not control: without it, such a URL can point the host at its own cloud metadata service or internal network.

It never uses a proxy, since a proxy would make the dialed address the proxy's and hide the real destination from the check.

func SameOriginAsFirstHop added in v2.17.0

func SameOriginAsFirstHop(req *http.Request) bool

SameOriginAsFirstHop reports whether req goes to the scheme and host of the request that started its redirect chain. A request that is not a redirect hop (req.Response nil) is its own first hop. A default port spelled out, such as port 443 on an https URL, is the same host as one left implicit.

func WithCredentialRedirectPolicy added in v2.17.0

func WithCredentialRedirectPolicy(c *http.Client) *http.Client

WithCredentialRedirectPolicy returns a copy of c whose CheckRedirect is CredentialRedirectPolicy, with c's own CheckRedirect run after it. c itself is never modified, so a client the caller shares (http.DefaultClient, a pooled client) keeps its own redirect behavior everywhere else. A nil c returns nil, so callers keep their own default-client logic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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