---
title: Request
summary: 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.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/struct.Request/
---

**Kind:** Struct  
**Module:** [fsthttp](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/)  
**Package:** compute-sdk-go v1.11.0  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L29

```go
type Request struct {
	Method string

	URL *url.URL

	Proto      string
	ProtoMajor int
	ProtoMinor int

	Header Header

	CacheOptions CacheOptions

	Body io.ReadCloser

	Host string

	RemoteAddr string

	ServerAddr string

	TLSInfo TLSInfo

	SendPollInterval time.Duration

	SendPollIntervalFn func(i int) time.Duration

	DecompressResponseOptions DecompressResponseOptions

	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

**Type:** `string`

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

### URL

**Type:** `*url.URL`

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

**Type:** `string`

Proto contains the HTTP protocol version used for incoming requests.

These fields are ignored for outgoing requests.

### ProtoMajor

**Type:** `int`

1

### ProtoMinor

**Type:** `int`

0

### Header

**Type:** `Header`

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

### CacheOptions

**Type:** `CacheOptions`

CacheOptions control caching behavior for outgoing requests.

### Body

**Type:** `io.ReadCloser`

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

**Type:** `string`

Host is the hostname parsed from the incoming request URL.

### RemoteAddr

**Type:** `string`

RemoteAddr contains the IP address of the requesting client.

This field is ignored for outgoing requests.

### ServerAddr

**Type:** `string`

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

This field is ignored for outgoing requests.

### TLSInfo

**Type:** `TLSInfo`

TLSInfo collects TLS metadata for incoming requests received over HTTPS.

### SendPollInterval

**Type:** `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

**Type:** `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

**Type:** `DecompressResponseOptions`

DecompressResponseOptions control the auto decompress response behaviour.

### ManualFramingMode

**Type:** `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

**Type:** `*imageopto.Options`

ImageOptimizerOptions control the image optimizer request.

## Methods

### AddCookie

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L376

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/bot.go#L85

```go
func (r *Request) BotDetection() (*BotDetectionResult, error)
```

**Returns**

`(*BotDetectionResult, error)`

### Clone

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L308

```go
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**

`*Request`

### CloneWithBody

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L330

```go
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**

`*Request`

### Close

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L268

```go
func (req *Request) Close() error
```

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

**Returns**

`error`

### Cookie

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L363

```go
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)`

### Cookies

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L352

```go
func (req *Request) Cookies() []*Cookie
```

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

**Returns**

`[]*Cookie`

### FastlyMeta

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L386

```go
func (req *Request) FastlyMeta() (*FastlyMeta, error)
```

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

**Returns**

`(*FastlyMeta, error)`

### HandoffFanout

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L1298

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L1277

```go
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`

### Inspect

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L1339

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

**Parameters**

- `opts`: `*InspectOptions`

**Returns**

`(*InspectResponse, error)`

### ResVPNProxyData

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/resvpnproxy.go#L35

```go
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**

`(*ResVPNProxyResult, error)`

### Send

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L464

```go
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](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/struct.Request/)'s [CacheOptions](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/struct.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)`

### SetBody

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L291

```go
func (req *Request) SetBody(body io.Reader)
```

SetBody sets the [Request](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/struct.Request/)'s body to the provided [io.Reader](https://pkg.go.dev/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](https://pkg.go.dev/bytes#Buffer),
[bytes.Reader](https://pkg.go.dev/bytes#Reader), or [strings.Reader](https://pkg.go.dev/strings#Reader), the runtime will send the
request with a Content-Length header instead of Transfer-Encoding:
chunked.

**Parameters**

- `body`: `io.Reader`

### TLSClientCertificateInfo

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/request.go#L1155

```go
func (req *Request) TLSClientCertificateInfo() (*TLSClientCertificateInfo, error)
```

**Returns**

`(*TLSClientCertificateInfo, error)`
