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

fetcher

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 18 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
}

Options configures a Fetcher.

Jump to

Keyboard shortcuts

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