httpx

package
v0.1.3-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

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 httpx is the HTTP layer: a shared client, retrying JSON reads and resumable-by-existence downloads.

The retry policy is ported from core/http.py's tenacity decorators rather than re-chosen. GitHub's API is polled unauthenticated here, so it is rate-limited, and loosening the policy would fail a sync that used to work.

Index

Constants

View Source
const (
	// UserAgent identifies the toolkit to the registries it polls.
	UserAgent = "icon-sets-sync (+https://github.com/ichava/icon-sets-sync)"

	// DefaultTimeout and DefaultDownloadTimeout match core/http.py.
	DefaultTimeout         = 30 * time.Second
	DefaultDownloadTimeout = 300 * time.Second

	// Attempts and the backoff bounds are tenacity's:
	// stop_after_attempt(4), wait_exponential(multiplier=2, min=2, max=30)
	// for JSON, and max=60 for downloads.
	Attempts = 4

	// DefaultMaxJSONBytes caps a version-discovery or registry response. The
	// largest real one is a few hundred KiB; 32 MiB is two orders above that.
	DefaultMaxJSONBytes int64 = 32 << 20

	// DefaultMaxDownloadBytes caps one archive download (S6). The largest
	// upstream archives are a few hundred MiB; 1 GiB leaves headroom without
	// letting a compromised upstream fill a runner's disk.
	DefaultMaxDownloadBytes int64 = 1 << 30
)

Variables

This section is empty.

Functions

func CheckScheme added in v0.1.3

func CheckScheme(raw string) error

CheckScheme enforces the https-only rule (P2-G6) on a configured URL. It knows nothing about hosts, so it is safe to run when a config loads, before the run-wide allowlist is in place.

func DefaultAllowedHosts added in v0.1.3

func DefaultAllowedHosts() []string

DefaultAllowedHosts returns the built-in allowlist, sorted. It is a copy.

func ParseHostList added in v0.1.3

func ParseHostList(raw string) []string

ParseHostList splits the `allowed_hosts` setting (comma or space separated) into lowercase, de-duplicated host names.

func SetExtraAllowedHosts added in v0.1.3

func SetExtraAllowedHosts(hosts []string)

SetExtraAllowedHosts sets the hosts every client allows beyond the defaults. It is the run-wide `allowed_hosts` setting, applied once at startup the way the private config directory is. Passing nil clears it.

Types

type Client

type Client struct {
	// Transport is the round tripper both the JSON and download clients are
	// built on. Tests supply a stub here rather than standing up an
	// httptest.Server: the sandbox this is developed in refuses to bind a
	// listening socket, and a suite that silently skips there would be the
	// same shape of false green this estate has been bitten by before.
	Transport http.RoundTripper

	// Sleep is swapped by tests so the retry path can be exercised without
	// waiting out the real backoff.
	Sleep func(time.Duration)

	// MaxJSONBytes and MaxDownloadBytes cap what one response body may hold.
	// Zero means the defaults below. Tests set them small.
	MaxJSONBytes     int64
	MaxDownloadBytes int64

	// AllowedHosts extends the built-in upstream allowlist for this client
	// only. The run-wide `allowed_hosts` setting reaches every client through
	// SetExtraAllowedHosts instead.
	AllowedHosts []string
}

Client performs the toolkit's HTTP requests.

func New

func New() *Client

New returns a client with the shared timeout.

func (*Client) CheckURL added in v0.1.3

func (c *Client) CheckURL(raw string) error

CheckURL is the rule for the first request of a fetch: https (or http to loopback), and a host on the allowlist (or loopback). GetJSON and Download run it before sending anything; it is exported so a test can ask the same question about a URL without fetching it.

func (*Client) Download

func (c *Client) Download(ctx context.Context, url, dest string, force bool) (string, error)

Download fetches url to dest and returns dest.

Idempotent by existence: a non-empty file already at dest is kept unless force is set. The write goes to a sibling .tmp and is renamed, so an interrupted download never leaves a truncated file that the next run would treat as a complete cache hit.

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, url string, out any) error

GetJSON fetches and decodes a JSON document.

Jump to

Keyboard shortcuts

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