Help us shape the future of Go! Take the 2026 Go Developer Survey

fetcher

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package fetcher retrieves a URL once per agent profile.

Index

Constants

View Source
const DefaultMaxBody = 5 << 20

DefaultMaxBody is the default response body cap (5 MiB).

Variables

This section is empty.

Functions

This section is empty.

Types

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher fetches URLs once per profile. Browser profiles get a full Chrome impersonation (TLS, HTTP/2 settings and default headers); bot profiles get a plain client that only sends the profile's own headers, because real crawlers do not send Chrome client hints.

func New

func New(opts Options) (*Fetcher, error)

New returns a Fetcher configured with opts.

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, url string, profile types.Profile) types.FetchResult

Fetch retrieves url using profile. Network failures are reported in the result rather than returned, so one failing profile never aborts a run.

func (*Fetcher) FetchAll

func (f *Fetcher) FetchAll(ctx context.Context, url string, profiles []types.Profile, concurrency int) []types.FetchResult

FetchAll fetches url once per profile, running at most concurrency requests at a time. Results keep the order of profiles.

func (*Fetcher) Get

func (f *Fetcher) Get(ctx context.Context, url, userAgent string, limit int64) (int, []byte, error)

Get performs a plain GET with the given user agent and returns at most limit bytes of the body. It is used for auxiliary files such as robots.txt.

type Options

type Options struct {
	// Timeout bounds each request, including reading the body.
	Timeout time.Duration
	// Headers are added to every request after the profile headers.
	Headers map[string]string
	// MaxBody caps how many body bytes are read and kept. Zero means DefaultMaxBody.
	MaxBody int64
	// Retries is how many times a request is retried after a network error
	// or a 502/504 gateway error. Other statuses are never retried because
	// they are exactly what acurl reports on.
	Retries int
	// Proxy is an http, https or socks5 proxy URL.
	Proxy string
	// Insecure skips TLS certificate verification.
	Insecure bool
	// HTTPVersion forces "1.1" or "2". Empty negotiates as a browser would.
	HTTPVersion string
	// Method is the HTTP method for page requests. Empty means GET.
	Method string
	// BotTLS selects the TLS fingerprint for non-browser profiles: "go"
	// (default, like most real crawlers) or "chrome" to make the user agent
	// the only difference from the browser baseline.
	BotTLS string
	// Trace, if set, is called after every page request.
	Trace func(TraceEvent)
	// Signer, if set, signs every bot-profile request (Web Bot Auth).
	Signer RequestSigner
	// BlockPrivate refuses connections to private, loopback and other
	// internal addresses (SSRF protection for acurl serve and mcp).
	BlockPrivate bool
}

Options configures a Fetcher.

type RequestSigner added in v0.4.0

type RequestSigner interface {
	Headers(method, url string) (map[string]string, error)
}

RequestSigner returns signature headers for a request.

type TraceEvent added in v0.3.0

type TraceEvent struct {
	Profile  string
	Method   string
	URL      string
	Status   int
	Duration time.Duration
	Err      error
}

TraceEvent describes one completed page request.

Jump to

Keyboard shortcuts

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