Documentation
¶
Overview ¶
Package network retrieves resources for the Growse browser.
Index ¶
- Variables
- func DefaultCacheRoot() (string, error)
- func RedactedDiagnosticURL(target *url.URL) string
- func RedactedURL(target *url.URL) string
- func SameOrigin(left, right *url.URL) bool
- type Client
- type CredentialsMode
- type HTTPCache
- func (cache *HTTPCache) InvalidateURL(request *Request, target *url.URL)
- func (cache *HTTPCache) Match(request *Request) (*Response, bool)
- func (cache *HTTPCache) MatchFresh(request *Request) (*Response, bool)
- func (cache *HTTPCache) MergeNotModified(request *Request, notModified http.Header) (*Response, bool)
- func (cache *HTTPCache) RevalidationHeaders(request *Request) (http.Header, bool)
- func (cache *HTTPCache) Store(request *Request, response *Response) bool
- type Observation
- type Origin
- type Request
- type RequestKind
- type Response
Constants ¶
This section is empty.
Variables ¶
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.
var ( ErrCORS = errors.New("CORS policy rejected the response") ErrCORSPreflightRequired = errors.New("CORS preflight is required") )
var ErrCacheValidation = errors.New("HTTP cache validation failed")
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
DefaultCacheRoot はOS標準Cache Directory配下のHTTP Cache rootを返す。
func RedactedDiagnosticURL ¶ added in v0.18.0
RedactedDiagnosticURL removes credentials, query, and fragment before a URL is retained in an error or diagnostic. Query values commonly contain tokens.
func RedactedURL ¶ added in v0.8.0
RedactedURL removes userinfo before a URL is included in user-visible state. Callers that retain a URL as a diagnostic must use RedactedDiagnosticURL.
func SameOrigin ¶ added in v0.8.0
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 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 ¶
NewClientWithLimits creates a client with explicit dependencies and limits. It is primarily useful for tests and alternative transports.
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
NewHTTPCacheWithDisk はmemory frontと永続Disk Cacheを持つprivate Cacheを生成する。
func (*HTTPCache) InvalidateURL ¶ added in v0.9.0
InvalidateURL はRequestと同じpartitionにあるURLのGET / HEAD variantをすべて削除する。
func (*HTTPCache) MatchFresh ¶ added in v0.9.0
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
RevalidationHeaders はstale/no-cache variantの条件付きRequest Headerを返す。
type Observation ¶ added in v0.12.0
type Observation struct {
Method string
URL *url.URL
FinalURL *url.URL
Kind RequestKind
Engine string
Initiator string
Schedule 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
Origin is the scheme, host, and effective port security boundary of a URL.
func OriginFromURL ¶ added in v0.8.0
OriginFromURL returns the normalized HTTP(S) origin of target.
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
CORS bool
Initiator string
Schedule string
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 ( RequestSubresource RequestForm RequestFetch RequestStylesheet RequestImage RequestFont RequestScript RequestModule RequestServiceWorker RequestServiceWorkerFetch )