pagereader

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 14 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 pagereader is our own page reader for the web_fetch built-in tool: it fetches the page itself and turns it into markdown, with no service in between and nothing to pay. It refuses private and local addresses, checked before every request and every redirect, and again on the address it actually connects to. A page built with JavaScript, a PDF, or a site that blocks plain fetches reads badly here; the jina reader is for those.

Index

Constants

This section is empty.

Variables

View Source
var ErrBlocked = errors.New("page-reader: not allowed")

ErrBlocked is what errors.Is finds for an address the reader must not reach.

Functions

func IsPrivateAddress

func IsPrivateAddress(s string) bool

IsPrivateAddress is true for an address the reader must never reach: loopback, private, link-local (cloud metadata), carrier NAT, multicast and reserved ranges, and an IPv6 address that maps onto one of them. Anything that is not an address at all is refused rather than guessed at.

Types

type Options

type Options struct {
	// MaxRedirects is the most redirects followed. Default 5.
	MaxRedirects int
	// Timeout is per page. Default 30s.
	Timeout   time.Duration
	UserAgent string
	// AllowPrivate reaches private and local addresses (127.0.0.1, 10.x,
	// 169.254.169.254, localhost…). Off by default: a prompt must never make
	// the agent read your cloud metadata or admin pages. For tests and local
	// development.
	AllowPrivate bool
	// Lookup is for tests: the addresses a host name resolves to.
	Lookup func(ctx context.Context, host string) ([]string, error)
	// Transport is for tests.
	Transport http.RoundTripper
}

Options shape a Reader. The zero value is the safe default.

type Reader

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

Reader is a ports.Fetcher that reads pages itself.

func New

func New(opts Options) *Reader

New is a page reader.

func (*Reader) Fetch

func (r *Reader) Fetch(ctx context.Context, target string, opts ports.FetchOptions) (ports.FetchedPage, error)

func (*Reader) Name

func (r *Reader) Name() string

Jump to

Keyboard shortcuts

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