Request
12345678910111213141516171819202122232425262728293031323334type Request struct { Method string
Proto string ProtoMajor int ProtoMinor int
Body io.ReadCloser
Host string
RemoteAddr string
ServerAddr string
SendPollInterval time.Duration
ManualFramingMode bool
// contains filtered or unexported fields}Request represents an HTTP request received by this server from a requesting client, or to be sent from this server during this execution. Some fields only have meaning in one context or the other.
Fields
URL
*url.URLURL is the parsed and validated URL of the request.
Outgoing requests are always sent to the preconfigured backend provided to the send method. The URL is used for the request resource, Host header, etc.
Proto contains the HTTP protocol version used for incoming requests.
These fields are ignored for outgoing requests.
Header
HeaderHeader contains the request header fields either received in the incoming request, or to be sent with the outgoing request.
CacheOptions
CacheOptionsCacheOptions control caching behavior for outgoing requests.
Body
io.ReadCloserBody is the request's body.
For the incoming client request, the body will always be non-nil, but reads may return immediately with EOF. For outgoing requests, the body is optional. A body may only be read once.
Prefer using the SetBody method over assigning to this value directly, as it enables optimizations when sending outgoing requests. See the SetBody documentation for more information.
RemoteAddr contains the IP address of the requesting client.
This field is ignored for outgoing requests.
ServerAddr contains the IP address of the server that received the HTTP request.
This field is ignored for outgoing requests.
TLSInfo
TLSInfoTLSInfo collects TLS metadata for incoming requests received over HTTPS.
SendPollInterval
time.DurationSendPollInterval determines how often the Send method will check for completed requests. While polling, the Go runtime is suspended, and all user code stops execution. A shorter interval will make Send more responsive, but provide less CPU time to user code. A longer poll interval will make Send less responsive, but provide more CPU time to user code.
If SendPollInterval is zero, a default value of 1ms is used. The minimum value is 1ms, and the maximum value is 1s.
SendPollIntervalFn allows more fine-grained control of the send poll interval.
SendPollIntervalFn must be a function which takes an iteration number i and returns the delay for the i'th polling interval.
DecompressResponseOptions
DecompressResponseOptionsDecompressResponseOptions control the auto decompress response behaviour.
ManualFramingMode controls how the framing headers (Content-Length/Transfer-Encoding) are set for a request.
If ManualFramingMode is true, the request uses the exact framing headers set in the message. If ManualFramingMode is false, or ManualFramingMode is true and the framing is invalid, the framing headers are based on the message body, and any framing headers already set in the message are discarded.
ImageOptimizerOptions
*imageopto.OptionsImageOptimizerOptions control the image optimizer request.
Methods
AddCookie
View sourceAddCookie adds a cookie to the request. Per RFC 6265 section 5.4, AddCookie does not attach more than one Cookie header field. That means all cookies, if any, are written into the same line, separated by semicolon. AddCookie only sanitizes c's name and value, and does not sanitize a Cookie header already present in the request.
Parameters
- c: *Cookie
Clone
View sourcefunc (req *Request) Clone() *RequestClone returns a copy of the request. The returned copy will have a nil Body field, and its URL will have a nil User field.
Returns
CloneWithBody
View sourceCloneWithBody returns a copy of the request, with the Body field set to the provided io.Reader. Its URL will have a nil User field.
Parameters
- body: io.Reader
Returns
Close
View sourcefunc (req *Request) Close() errorClose releases the request resources if it is not going to be passed to Send.
Returns
Cookie
View sourceCookie returns the named cookie provided in the request or ErrNoCookie if not found. If multiple cookies match the given name, only one cookie will be returned.
Parameters
- name: string
Returns
Cookies
View sourceCookies parses and returns the HTTP cookies sent with the request.
Returns
FastlyMeta
View sourceFastlyMeta returns a fleshed-out FastlyMeta object for the request.
Returns
HandoffFanout
View sourcefunc (r *Request) HandoffFanout(backend string) errorHandoffFanout passes the request through the Fanout GRIP proxy and on to a backend.
This can only be used on services that have the Fanout feature enabled.
The sending completes in the background. Once this method has been called, no other response can be sent to this request, and the application can exit without affecting the send.
Parameters
- backend: string
Returns
HandoffWebsocket
View sourcefunc (r *Request) HandoffWebsocket(backend string) errorHandoffWebsocket passes the WebSocket directly to a backend.
This can only be used on services that have the WebSockets feature enabled and on requests that are valid WebSocket requests. The sending completes in the background.
Once this method has been called, no other response can be sent to this request, and the application can exit without affecting the send.
Parameters
- backend: string
Returns
ResVPNProxyData
View sourceResVPNProxyData analyzes the current downstream request's IP address and returns VPN and proxy intelligence data.
Response will return the field "Available" as false if the ResVPNProxy dataset is not enabled for the service.
Example usage:
vpnData, err := r.ResVPNProxyData()if err != nil { return err}Returns
Send
View sourceSend the request to the named backend. Requests may only be sent to backends that have been preconfigured in your service, regardless of their URL. Once sent, a request cannot be sent again.
By default, read-through caching is enabled for requests. The HTTP response received from the backend will be cached and reused for subsequent requests if it meets cacheability requirements. The behavior of this automatic caching can be tuned (or disabled) via the Request's CacheOptions field. This function provides the full benefits of Fastly's purging, request collapsing, and revalidation capabilities, and is recommended for most users who need to cache HTTP responses.
Parameters
- ctx: context.Context
- backend: string
Returns
SetBody
View sourceSetBody sets the Request's body to the provided io.Reader. Prefer using this method over setting the Body field directly, as it enables optimizations in the runtime.
If an unread body from an incoming client request is set on an outgoing upstream request, the body will be efficiently streamed from the incoming request. It is also possible to set the unread body of a received response to the body of a request, with the same results.
If the body is set from an in-memory reader such as bytes.Buffer, bytes.Reader, or strings.Reader, the runtime will send the request with a Content-Length header instead of Transfer-Encoding: chunked.
Parameters
- body: io.Reader