Request

Structin fsthttpcompute-sdk-go v1.11.0View source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
type Request struct {
Method string
URL *url.URL
Proto string
ProtoMajor int
ProtoMinor int
Host string
RemoteAddr string
ServerAddr string
SendPollInterval time.Duration
SendPollIntervalFn func(i int) time.Duration
ManualFramingMode bool
ImageOptimizerOptions *imageopto.Options
// 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

Method

string

Method specifies the HTTP method: GET, POST, PUT, HEAD, etc.

URL 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

string

Proto contains the HTTP protocol version used for incoming requests.

These fields are ignored for outgoing requests.

ProtoMajor

int

1

ProtoMinor

int

0

Header

Header

Header contains the request header fields either received in the incoming request, or to be sent with the outgoing request.

CacheOptions

CacheOptions

CacheOptions control caching behavior for outgoing requests.

Body 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.

Host

string

Host is the hostname parsed from the incoming request URL.

RemoteAddr

string

RemoteAddr contains the IP address of the requesting client.

This field is ignored for outgoing requests.

ServerAddr

string

ServerAddr contains the IP address of the server that received the HTTP request.

This field is ignored for outgoing requests.

TLSInfo

TLSInfo

TLSInfo collects TLS metadata for incoming requests received over HTTPS.

SendPollInterval

time.Duration

SendPollInterval 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

func(i int) time.Duration

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

DecompressResponseOptions

DecompressResponseOptions control the auto decompress response behaviour.

ManualFramingMode

bool

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.Options

ImageOptimizerOptions control the image optimizer request.

Methods

AddCookie

View source
func (req *Request) AddCookie(c *Cookie)

AddCookie 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

BotDetection

View source
func (r *Request) BotDetection() (*BotDetectionResult, error)

Returns

func (req *Request) Clone() *Request

Clone 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 source
func (req *Request) CloneWithBody(body io.Reader) *Request

CloneWithBody 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

func (req *Request) Close() error

Close releases the request resources if it is not going to be passed to Send.

Returns

error
func (req *Request) Cookie(name string) (*Cookie, error)

Cookie 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

(*Cookie, error)
func (req *Request) Cookies() []*Cookie

Cookies parses and returns the HTTP cookies sent with the request.

Returns

FastlyMeta

View source
func (req *Request) FastlyMeta() (*FastlyMeta, error)

FastlyMeta returns a fleshed-out FastlyMeta object for the request.

Returns

(*FastlyMeta, error)

HandoffFanout

View source
func (r *Request) HandoffFanout(backend string) error

HandoffFanout 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

error

HandoffWebsocket

View source
func (r *Request) HandoffWebsocket(backend string) error

HandoffWebsocket 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

error
func (r *Request) Inspect(opts *InspectOptions) (*InspectResponse, error)

Parameters

opts: *InspectOptions

Returns

(*InspectResponse, error)

ResVPNProxyData

View source
func (r *Request) ResVPNProxyData() (*ResVPNProxyResult, error)

ResVPNProxyData 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

func (req *Request) Send(ctx context.Context, backend string) (*Response, error)

Send 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

(*Response, error)
func (req *Request) SetBody(body io.Reader)

SetBody 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

TLSClientCertificateInfo

View source
func (req *Request) TLSClientCertificateInfo() (*TLSClientCertificateInfo, error)

Returns