Documentation
¶
Index ¶
- Variables
- func CanonicalHeaderKey(key string) string
- type Client
- type Cookie
- type CookieJar
- type Header
- func (h Header) Add(key, value string)
- func (h Header) Clone() (newHeader Header)
- func (h Header) Del(key string)
- func (h Header) Get(key string) (value string)
- func (h Header) Has(key string) (has bool)
- func (h Header) Set(key, value string)
- func (h Header) Values() (values []string)
- func (h Header) Write(w io.Writer) error
- func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error
- type Request
- func (r *Request) AddCookie(c *Cookie)
- func (r *Request) BasicAuth() (username, password string, ok bool)
- func (r *Request) Clone() (newRequest *Request)
- func (r *Request) Context() context.Context
- func (r *Request) Cookie(name string) (*Cookie, error)
- func (r *Request) Cookies() []*Cookie
- func (r *Request) CookiesNamed(name string) []*Cookie
- func (r *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (r *Request) FormValue(key string) string
- func (r *Request) MultipartReader() (*multipart.Reader, error)
- func (r *Request) ParseForm() error
- func (r *Request) ParseMultipartForm(maxMemory int64) error
- func (r *Request) PostFormValue(key string) string
- func (r *Request) ProtoAtLeast(major, minor int) bool
- func (r *Request) Referer() string
- func (r *Request) SetBasicAuth(username, password string)
- func (r *Request) UserAgent() string
- func (r *Request) WithContext(ctx context.Context) *Request
- func (r *Request) Write(w io.Writer) error
- func (r *Request) WriteProxy(w io.Writer) error
- type Response
- type RoundTripper
- type SameSite
- type Transport
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = Fetch
DefaultClient is an alias for Fetch.
var Fetch = &Client{ Transport: FetchRoundTripper, Timeout: 20 * time.Second, }
Fetch is a fetch client. It is used to make requests. It wraps around JS fetch.
Functions ¶
func CanonicalHeaderKey ¶
Types ¶
type Client ¶
type Client struct {
// Transport specifies the mechanism by which individual requests are made.
// If nil, FetchRoundTripper is used.
Transport RoundTripper
// Jar does nothing, but it is required for compatibility with the Go standard library.
Jar CookieJar
// Timeout specifies a time limit for requests made by this Client.
Timeout time.Duration
}
Client is a fetch client. It is used to make requests.
type Cookie ¶
type Cookie struct {
Name string
Value string
Quoted bool
Path string
Domain string
Expires time.Time
RawExpires string
MaxAge int
Secure bool
HttpOnly bool
SameSite SameSite
Partitioned bool
Raw string
Unparsed []string
}
Cookie does nothing, but it is required for compatibility with the Go standard library.
type CookieJar ¶
type CookieJar interface {
SetCookies(u *url.URL, cookies []*Cookie)
Cookies(u *url.URL) []*Cookie
}
CookieJar does nothing, but it is required for compatibility with the Go standard library.
type Request ¶
type Request struct {
// DisableStreamedClient specifies whether to use a streamed client body.
// This is set to false by default, but has checks to make sure it's running on a supported browser.
// HTTP/2 or QUIC to be enabled when using V8, which is not always the case, particularly on
// older servers or test servers.
//
// If DisableStreamedClientChecks is set to false, the client will first attempt to detect if
// the server supports HTTP/2 or QUIC and if you are running a supported JavaScript engine.
// Supported browser engines include:
// - V8 (Chrome, Edge, Opera)
// Unsupported browser engines include:
// - SpiderMonkey (Firefox)
// - JavaScriptCore (Safari)
// - Chakra (Internet Explorer)
// - KJS (Konqueror)
// - Presto (Opera Mini and ancient versions of Opera)
// Data from https://caniuse.com/mdn-api_request_request_request_body_readablestream
// TL;DR If it's chromium it'll work.
DisableStreamedClient bool
// DisableStreamedClientChecks specifies whether to disable checks for streamed clients.
// It does nothing if UseStreamedClient is set to false.
// Having it set to false may add another HEAD request to the server, which may be undesirable.
// Also, forcing it on may be useful if SpiderMonkey one day supports streamed clients bodies.
DisableStreamedClientChecks bool
// Method specifies the HTTP method (GET, POST, PUT, etc.).
Method string
// URL specifies either the URL to fetch as a string, or a URL object.
URL *url.URL
// Headers is a Headers object, allowing you to set request headers.
Header Header
// Body is an optional body to be sent with the request.
Body io.ReadCloser
// GetBody is an optional function that returns a ReadCloser for the body.
GetBody func() (io.ReadCloser, error)
// ContentLength is the length of the body. It is mostly superseded by the Content-Length header.
ContentLength int64
// Proto, ProtoMajor, ProtoMinor specify the HTTP protocol version.
// This is useless, as fetch does not allow you to specify the protocol version.
Proto string
ProtoMajor int
ProtoMinor int
// Close indicates whether to close the connection after the request.
// This is useless, as fetch does not allow you to specify whether to close the connection and instead forces you to use a WebSocket.
Close bool
// Host specifies the host to perform the request to.
// This is useless, as it only makes sense in the context of the Host or :authority headers, both of which are filled-in automatically by fetch.
Host string
// TransferEncoding specifies the transfer encodings to be used.
// This is useless, as since we always use a stream, the transfer encoding is always chunked.
TransferEncoding []string
// Form, PostForm, and MultipartForm specify the parsed form data.
// This is useless, because even the Go standard library does not use it.
// Use Body instead.
Form url.Values
PostForm url.Values
MultipartForm *url.Values
// Trailer specifies additional headers that are sent after the request body.
// This is useless, as fetch does not allow you to specify trailers.
// Not to mention, nothing supports trailers.
Trailer Header
// RemoteAddr and RequestURI specify the remote address and Request-URI for the request.
// This is useless, as fetch does not allow you to specify the remote address, and you should use URL instead of RequestURI.
RemoteAddr string
RequestURI string
// TLS allows you to specify the TLS connection state.
// This is useless, as fetch does not allow you to specify the TLS connection state.
TLS *tls.ConnectionState
// Cancel is an optional channel that can be used to cancel the request.
// This isn't even in the Go standard library anymore.
Cancel <-chan struct{}
// Response is the response that caused this request to be created, usually in a redirect.
// This is useless, as fetch follows redirects automatically.
Response *Response
// Pattern is the pattern that was matched for this request.
// This is useless, as fetch does not support pattern matching.
Pattern string
}
func (*Request) AddCookie ¶
AddCookie does nothing, but it is required for compatibility with the Go standard library.
func (*Request) BasicAuth ¶
BasicAuth does nothing, but it is required for compatibility with the Go standard library.
func (*Request) Context ¶
Context does nothing, but it is required for compatibility with the Go standard library.
func (*Request) Cookie ¶
Cookie does nothing, but it is required for compatibility with the Go standard library.
func (*Request) Cookies ¶
Cookies does nothing, but it is required for compatibility with the Go standard library.
func (*Request) CookiesNamed ¶
CookiesNamed does nothing, but it is required for compatibility with the Go standard library.
func (*Request) FormFile ¶
FormFile does nothing, but it is required for compatibility with the Go standard library.
func (*Request) FormValue ¶
FormValue does nothing, but it is required for compatibility with the Go standard library.
func (*Request) MultipartReader ¶
MultipartReader does nothing, but it is required for compatibility with the Go standard library.
func (*Request) ParseForm ¶
ParseForm does nothing, but it is required for compatibility with the Go standard library.
func (*Request) ParseMultipartForm ¶
ParseMultipartForm does nothing, but it is required for compatibility with the Go standard library.
func (*Request) PostFormValue ¶
PostFormValue does nothing, but it is required for compatibility with the Go standard library.
func (*Request) ProtoAtLeast ¶
ProtoAtLeast does nothing, but it is required for compatibility with the Go standard library.
func (*Request) SetBasicAuth ¶
SetBasicAuth does nothing, but it is required for compatibility with the Go standard library.
func (*Request) WithContext ¶
WithContext does nothing, but it is required for compatibility with the Go standard library.
type Response ¶
type Response struct {
// Status specifies the HTTP status.
// It will be an empty string if using HTTP/2.
Status string
// StatusCode specifies the HTTP status code.
StatusCode int
// Header specifies the response headers.
Header Header
// Body is the response body.
Body io.ReadCloser
// TransferEncoding specifies the transfer encodings that have been applied to the response.
TransferEncoding []string
// ContentLength specifies the length of the body.
// It is mostly superseded by the Content-Length header.
// A value of -1 indicates that the length is unknown.
ContentLength int64
// Request is the request that was made to get this response.
Request *Request
// Proto, ProtoMajor, ProtoMinor specify the HTTP protocol version.
// This is useless, as fetch does not allow you to specify the protocol version.
Proto string
ProtoMajor int
ProtoMinor int
// Close indicates whether to close the connection after the request.
// This is useless, as fetch does not allow you to specify whether to close the connection and instead forces you to use a WebSocket.
Close bool
// Uncompressed specifies whether the response is uncompressed.
// This is useless, as fetch does not allow you to specify whether the response is uncompressed.
Uncompressed bool
// Trailer specifies additional headers that are sent after the request body.
// This is useless, as fetch does not allow you to specify trailers.
// Not to mention, nothing supports trailers.
Trailer Header
// TLS allows you to specify the TLS connection state.
// This is useless, as fetch does not allow you to specify the TLS connection state.
TLS *tls.ConnectionState
}
func (*Response) Cookies ¶
Cookies does nothing, but it is required for compatibility with the Go standard library.
func (*Response) ProtoAtLeast ¶
ProtoAtLeast does nothing, but it is required for compatibility with the Go standard library.
type RoundTripper ¶
type RoundTripper interface {
// RoundTrip executes a single HTTP transaction, returning a Response for the provided Request.
// In the context of fetch, it will automatically follow redirects.
RoundTrip(*Request) (*Response, error)
}
RoundTripper is an interface representing the ability to execute a single HTTP transaction.
var FetchRoundTripper RoundTripper = &Transport{}
FetchRoundTripper is a wrapper around the fetch API. It is used to make requests. It is the default RoundTripper used for this subset of net/http.
type SameSite ¶
type SameSite int
SameSite does nothing, but it is required for compatibility with the Go standard library.
type Transport ¶
type Transport struct {
// Proxy specifies a function to return a proxy for a given Request.
// It is ignored in fetch.
Proxy func(*Request) (*url.URL, error)
// OnProxyError specifies a function to handle errors that occur while fetching a proxy.
// It is ignored in fetch.
OnProxyError func(*Request, *url.URL, error)
// DialContext specifies the dial function for creating unencrypted TCP connections.
// It is ignored in fetch.
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
// Dial specifies the dial function for creating unencrypted TCP connections.
// It is ignored in fetch.
Dial func(network, addr string) (net.Conn, error)
// DialTLSContext specifies the dial function for creating TLS connections.
// It is ignored in fetch.
DialTLSContext func(ctx context.Context, network, addr string) (net.Conn, error)
// DialTLS specifies the dial function for creating TLS connections.
// It is ignored in fetch.
DialTLS func(network, addr string) (net.Conn, error)
// TLSClientConfig specifies the TLS configuration to use with tls.Client.
// It is ignored in fetch.
TLSClientConfig *tls.Config
// TLSHandshakeTimeout specifies the maximum amount of time waiting to wait for a TLS handshake.
// It is ignored in fetch.
TLSHandshakeTimeout time.Duration
// DisableKeepAlives specifies whether to disable keep-alive connections.
// It is ignored in fetch.
DisableKeepAlives bool
// DisableCompression specifies whether to disable compression.
// It is ignored in fetch.
DisableCompression bool
// MaxIdleConns specifies the maximum number of idle (keep-alive) connections to keep.
// It is ignored in fetch.
MaxIdleConns int
// MaxIdleConnsPerHost specifies the maximum number of idle (keep-alive) connections to keep per host.
// It is ignored in fetch.
MaxIdleConnsPerHost int
// IdleConnTimeout specifies the maximum amount of time an idle (keep-alive) connection will remain idle before closing itself.
// It is ignored in fetch.
IdleConnTimeout time.Duration
// ResponseHeaderTimeout specifies the maximum amount of time to wait for a response header.
// It is ignored in fetch.
ResponseHeaderTimeout time.Duration
// ExpectContinueTimeout specifies the maximum amount of time to wait for a 100-continue response.
// It is ignored in fetch.
ExpectContinueTimeout time.Duration
// TLSNextProto specifies a function to upgrade the connection to a different protocol.
// It is ignored in fetch.
TLSNextProto map[string]func(authority string, c net.Conn) RoundTripper
// ProxyConnectHeader specifies the headers to send to proxies during CONNECT requests.
// It is ignored in fetch.
ProxyConnectHeader Header
// MaxResponseHeaderBytes specifies the maximum number of bytes to read from the server's response headers.
// It is ignored in fetch.
MaxResponseHeaderBytes int
// WriteBufferSize specifies the size of the write buffer.
// It is ignored in fetch.
WriteBufferSize int
// ReadBufferSize specifies the size of the read buffer.
// It is ignored in fetch.
ReadBufferSize int
// ForceAttemptHTTP2 specifies whether to force an attempt to use HTTP/2.
// It is ignored in fetch.
ForceAttemptHTTP2 bool
}
Transport is here only for compatibility with the Go standard library. All fields are ignored in fetch.
func (*Transport) CloseIdleConnections ¶
func (t *Transport) CloseIdleConnections()
CloseIdleConnections closes any idle connections. This does nothing in fetch.
func (*Transport) RegisterProtocol ¶
func (t *Transport) RegisterProtocol(protocol string, rt RoundTripper)
RegisterProtocol registers a new protocol with a custom RoundTripper. This does nothing in fetch.