httpx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 12 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
)

Variables

This section is empty.

Functions

This section is empty.

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)
}

Client performs the toolkit's HTTP requests.

func New

func New() *Client

New returns a client with the shared timeout.

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