httpclient

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package httpclient provides a centralized HTTP client factory with preset configurations.

Index

Constants

View Source
const (
	// DefaultTimeout is the standard timeout for most HTTP requests (30s).
	DefaultTimeout = 30 * time.Second

	// LongTimeout is for operations that may take longer (60s).
	LongTimeout = 60 * time.Second
)

Preset timeout durations for common use cases.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) *http.Client

New creates a new HTTP client with the given options. If no timeout is specified, DefaultTimeout (30s) is used.

func NewDefault

func NewDefault() *http.Client

NewDefault creates a new HTTP client with the default timeout (30s).

func NewForExternal added in v0.3.0

func NewForExternal(net NetworkProxyConfig, timeout time.Duration) *http.Client

NewForExternal builds a proxy-aware *http.Client with the given timeout, reading proxy settings from the supplied config. Used by every external integration (Prowlarr, SABnzbd, NZBLNK resolver, Arrs). Internal endpoints should NOT use this — call New() or use http.DefaultClient instead.

A nil net argument disables proxying.

func NewLong

func NewLong() *http.Client

NewLong creates a new HTTP client with a longer timeout (60s). Suitable for operations that may take longer, such as external API calls.

Types

type NetworkProxyConfig added in v0.3.0

type NetworkProxyConfig interface {
	GetHTTPProxy() string
	GetHTTPSProxy() string
	GetNoProxy() string
}

NetworkProxyConfig is the minimal interface the factory needs from the application config. Implemented by config.NetworkConfig — declared here to avoid an internal/config ↔ internal/httpclient import cycle.

type Option

type Option func(*Options)

Option is a functional option for configuring HTTP clients.

func WithProxyConfig added in v0.3.0

func WithProxyConfig(httpProxy, httpsProxy, noProxy string) Option

WithProxyConfig returns an Option that installs a proxy-aware *http.Transport derived from the supplied values. Pass empty strings to disable proxying.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the client timeout.

type Options

type Options struct {
	Timeout   time.Duration
	Transport *http.Transport
}

Options configures an HTTP client.

Jump to

Keyboard shortcuts

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