network

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package network retrieves resources for the Growse browser.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResponseTooLarge  = errors.New("response body is too large")
	ErrResponseTruncated = errors.New("response body was truncated")
	ErrRedirectLoop      = errors.New("redirect loop")
	ErrRedirectLimit     = errors.New("redirect limit exceeded")
	ErrTimeout           = errors.New("request timed out")
	ErrRequestTooLarge   = errors.New("request exceeds safety limit")
	ErrHeadersTooLarge   = errors.New("HTTP headers exceed safety limit")
)

ErrResponseTooLarge is returned when a response exceeds the configured body-size limit.

View Source
var (
	ErrCORS                  = errors.New("CORS policy rejected the response")
	ErrCORSPreflightRequired = errors.New("CORS preflight is required")
)
View Source
var ErrCacheValidation = errors.New("HTTP cache validation failed")
View Source
var ErrInvalidOrigin = errors.New("invalid HTTP origin")

ErrInvalidOrigin reports a URL that cannot identify an HTTP(S) origin.

Functions

func DefaultCacheRoot added in v0.9.0

func DefaultCacheRoot() (string, error)

DefaultCacheRoot はOS標準Cache Directory配下のHTTP Cache rootを返す。

func RedactedURL added in v0.8.0

func RedactedURL(target *url.URL) string

RedactedURL removes userinfo before a URL is included in UI or errors.

func SameOrigin added in v0.8.0

func SameOrigin(left, right *url.URL) bool

SameOrigin reports whether two URLs share scheme, host, and effective port.

Types

type Client

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

Client is a size-limited HTTP resource loader.

func NewClient

func NewClient() *Client

NewClient creates a client with production defaults.

func NewClientWithCacheRoot added in v0.9.0

func NewClientWithCacheRoot(httpClient *http.Client, maxBodyBytes int64, cacheRoot string) (*Client, error)

NewClientWithCacheRoot creates a client whose disposable HTTP Cache is persisted below the explicitly supplied cache root.

func NewClientWithLimits

func NewClientWithLimits(httpClient *http.Client, maxBodyBytes int64) *Client

NewClientWithLimits creates a client with explicit dependencies and limits. It is primarily useful for tests and alternative transports.

func (*Client) Do added in v0.8.0

func (c *Client) Do(ctx context.Context, requestData *Request) (result *Response, resultErr error)

Do sends a size-limited HTTP request.

func (*Client) Get

func (c *Client) Get(ctx context.Context, resourceURL *url.URL) (*Response, error)

Get retrieves one HTTP(S) resource.

type CredentialsMode added in v0.8.0

type CredentialsMode string

CredentialsMode controls whether Fetch sends and stores credentials.

const (
	CredentialsOmit       CredentialsMode = "omit"
	CredentialsSameOrigin CredentialsMode = "same-origin"
	CredentialsInclude    CredentialsMode = "include"
)

type HTTPCache added in v0.9.0

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

HTTPCache はprivate HTTP Response variantをmemoryで管理する。

func NewHTTPCache added in v0.9.0

func NewHTTPCache() *HTTPCache

func NewHTTPCacheWithDisk added in v0.9.0

func NewHTTPCacheWithDisk(cacheRoot string) (*HTTPCache, error)

NewHTTPCacheWithDisk はmemory frontと永続Disk Cacheを持つprivate Cacheを生成する。

func (*HTTPCache) InvalidateURL added in v0.9.0

func (cache *HTTPCache) InvalidateURL(request *Request, target *url.URL)

InvalidateURL はRequestと同じpartitionにあるURLのGET / HEAD variantをすべて削除する。

func (*HTTPCache) Match added in v0.9.0

func (cache *HTTPCache) Match(request *Request) (*Response, bool)

Match はRequest Headerを含めて一致する保存済みvariantを返す。

func (*HTTPCache) MatchFresh added in v0.9.0

func (cache *HTTPCache) MatchFresh(request *Request) (*Response, bool)

func (*HTTPCache) MergeNotModified added in v0.9.0

func (cache *HTTPCache) MergeNotModified(request *Request, notModified http.Header) (*Response, bool)

MergeNotModified は304 Headerを保存済みentryへmergeしてBody付きResponseを返す。

func (*HTTPCache) RevalidationHeaders added in v0.9.0

func (cache *HTTPCache) RevalidationHeaders(request *Request) (http.Header, bool)

RevalidationHeaders はstale/no-cache variantの条件付きRequest Headerを返す。

func (*HTTPCache) Store added in v0.9.0

func (cache *HTTPCache) Store(request *Request, response *Response) bool

Store はCache対象Request/Responseをvariantとして保存する。

type Observation added in v0.12.0

type Observation struct {
	Method        string
	URL           *url.URL
	Kind          RequestKind
	Engine        string
	StartedAt     time.Time
	Duration      time.Duration
	StatusCode    int
	Redirected    bool
	CacheStatus   string
	ResponseBytes int
	ErrorCategory string
}

Observation is body-free request metadata emitted after one client operation.

type Origin added in v0.8.0

type Origin struct {
	Scheme string
	Host   string
	Port   string
}

Origin is the scheme, host, and effective port security boundary of a URL.

func OriginFromURL added in v0.8.0

func OriginFromURL(target *url.URL) (Origin, error)

OriginFromURL returns the normalized HTTP(S) origin of target.

func (Origin) String added in v0.8.0

func (origin Origin) String() string

String serializes an origin for the HTTP Origin header.

type Request added in v0.8.0

type Request struct {
	Method      string
	URL         *url.URL
	Header      http.Header
	Body        []byte
	SiteURL     *url.URL
	Kind        RequestKind
	Engine      string
	Credentials CredentialsMode
	Observer    func(Observation)
}

Request contains the HTTP request data accepted by the network client.

type RequestKind added in v0.8.0

type RequestKind uint8

RequestKind identifies the browser operation that initiated a request.

const (
	RequestNavigation RequestKind = iota
	RequestSubresource
	RequestForm
	RequestFetch
	RequestStylesheet
	RequestImage
	RequestScript
)

type Response

type Response struct {
	URL         *url.URL
	StatusCode  int
	Status      string
	Header      http.Header
	ContentType string
	Body        []byte
	Redirected  bool
	CacheStatus string
}

Response contains the network metadata needed to construct a browser page.

Jump to

Keyboard shortcuts

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