Documentation
¶
Overview ¶
Package fetch provides the HTTP API exposed to WebGo programs.
Index ¶
- Constants
- Variables
- type API
- type AbortController
- type AbortSignal
- type Clock
- type CredentialsMode
- type Header
- type HeaderEntry
- type Headers
- func (headers *Headers) Append(name, value string) error
- func (headers *Headers) Clone() *Headers
- func (headers *Headers) Delete(name string)
- func (headers *Headers) Entries() []HeaderEntry
- func (headers *Headers) Get(name string) (string, bool)
- func (headers *Headers) Has(name string) bool
- func (headers *Headers) Set(name, value string) error
- func (headers *Headers) Values(name string) []string
- type Limiter
- type Request
- type Response
- type ResponseHeaders
- type Timer
Constants ¶
const ( Millisecond time.Duration = time.Millisecond Second time.Duration = time.Second )
Variables ¶
var ( ErrInvalidHeader = errors.New("invalid Fetch header") ErrForbiddenHeader = errors.New("forbidden Fetch request header") ErrHeadersTooLarge = errors.New("Fetch headers exceed size limit") )
var ErrBodyConsumed = errors.New("response body has already been consumed")
ErrBodyConsumed reports a second attempt to consume one response body.
var ErrInvalidText = errors.New("response body is not valid UTF-8")
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API binds WebGo Fetch calls to one page URL and network executor.
func New ¶
func New(baseURL *url.URL, do func(context.Context, *network.Request) (*network.Response, error)) *API
New creates a page-scoped Fetch API.
func NewPage ¶
func NewPage(ctx context.Context, baseURL *url.URL, do func(context.Context, *network.Request) (*network.Response, error), enqueue func(func()) bool) *API
NewPage creates an asynchronous Fetch API bound to a page callback queue.
func NewPageWithClock ¶ added in v0.11.0
func (*API) Close ¶
func (api *API) Close()
Close rejects new Fetches and waits for all request goroutines to release references.
func (*API) SetLimiter ¶ added in v0.11.0
type AbortController ¶ added in v0.11.0
type AbortController struct {
// contains filtered or unexported fields
}
AbortController owns one signal used to cancel Fetch requests.
func NewAbortController ¶ added in v0.11.0
func NewAbortController() *AbortController
NewAbortController creates a controller with an active signal.
func (*AbortController) Abort ¶ added in v0.11.0
func (controller *AbortController) Abort()
Abort cancels the signal. Repeated calls are harmless.
func (*AbortController) Signal ¶ added in v0.11.0
func (controller *AbortController) Signal() *AbortSignal
Signal returns this controller's signal.
type AbortSignal ¶ added in v0.11.0
type AbortSignal struct {
// contains filtered or unexported fields
}
AbortSignal is a read-only cancellation state for a Fetch request.
func (*AbortSignal) Aborted ¶ added in v0.11.0
func (signal *AbortSignal) Aborted() bool
Aborted reports whether the signal has been canceled.
type CredentialsMode ¶
type CredentialsMode string
CredentialsMode controls Cookie and HTTP authentication handling.
const ( CredentialsOmit CredentialsMode = "omit" CredentialsSameOrigin CredentialsMode = "same-origin" CredentialsInclude CredentialsMode = "include" )
type HeaderEntry ¶ added in v0.11.0
type HeaderEntry struct{ Name, Value string }
HeaderEntry is one ordered HTTP field name/value pair.
type Headers ¶ added in v0.11.0
type Headers struct {
// contains filtered or unexported fields
}
Headers stores ordered HTTP fields while preserving repeated values.
func NewHeaders ¶ added in v0.11.0
func NewHeaders() *Headers
NewHeaders creates an empty request header collection.
func (*Headers) Entries ¶ added in v0.11.0
func (headers *Headers) Entries() []HeaderEntry
Entries returns a defensive ordered copy.
type Limiter ¶ added in v0.11.0
type Limiter struct {
// contains filtered or unexported fields
}
Limiter bounds in-flight Fetch operations shared by a browser session.
func NewLimiter ¶ added in v0.11.0
type Request ¶
type Request struct {
Method string
URL string
Header Header
Headers *Headers
Body []byte
Text string
JSON string
Params *urlapi.URLSearchParams
FormData *formapi.FormData
Signal *AbortSignal
Timeout time.Duration
Credentials CredentialsMode
}
Request describes an HTTP request issued by a WebGo program. Body takes precedence over Text when both are set.
type Response ¶
type Response struct {
Status int
StatusText string
URL string
Redirected bool
Header Header
Headers *ResponseHeaders
// contains filtered or unexported fields
}
Response is delivered to a successful Fetch callback. Additional response metadata and body helpers are added by the HTTP lifecycle implementation.
type ResponseHeaders ¶ added in v0.11.0
type ResponseHeaders struct {
// contains filtered or unexported fields
}
ResponseHeaders is an immutable, defensive view of response fields.
func (*ResponseHeaders) Entries ¶ added in v0.11.0
func (headers *ResponseHeaders) Entries() []HeaderEntry
func (*ResponseHeaders) Get ¶ added in v0.11.0
func (headers *ResponseHeaders) Get(name string) (string, bool)
func (*ResponseHeaders) Values ¶ added in v0.11.0
func (headers *ResponseHeaders) Values(name string) []string