http

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package http provides HTTP utilities for fetching remote resources.

Index

Constants

View Source
const (
	// UserAgentName is the application name used in the User-Agent header.
	UserAgentName = "tinct"

	// DefaultTimeout is the default HTTP request timeout.
	DefaultTimeout = 10 * time.Second

	// DefaultMaxResponseBytes is the maximum response body size (500 MB).
	// Prevents memory exhaustion from malicious or unexpectedly large responses.
	DefaultMaxResponseBytes int64 = 500 * 1024 * 1024
)

Variables

This section is empty.

Functions

func Fetch

func Fetch(ctx context.Context, url string, opts FetchOptions) ([]byte, error)

Fetch retrieves content from a URL with context and timeout support. It automatically sets the User-Agent header and handles common HTTP errors.

Types

type FetchOptions

type FetchOptions struct {
	// Timeout specifies the HTTP request timeout.
	// If zero, DefaultTimeout is used.
	Timeout time.Duration

	// Headers specifies additional HTTP headers to send with the request.
	Headers map[string]string

	// ProgressCallback is called periodically with download progress.
	// Arguments are: bytesDownloaded, totalBytes (or -1 if unknown).
	ProgressCallback func(current, total int64)

	// MaxResponseBytes limits the maximum response body size.
	// If zero, DefaultMaxResponseBytes is used.
	// Set to -1 to disable the limit (not recommended).
	MaxResponseBytes int64
}

FetchOptions configures HTTP fetch behavior.

Jump to

Keyboard shortcuts

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