---
title: Transport
summary: Transport is an http.RoundTripper implementation for backend requests on Compute.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/struct.Transport/
---

**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/transport.go#L26

```go
type Transport struct {
	Request func(req *Request) error
	// contains filtered or unexported fields
}
```

Transport is an http.RoundTripper implementation for backend requests
on Compute.

Compute requests must be made to a pre-configured named backend.
Transport provides a mechanism for mapping hostnames to backend
names.  A default catchall backend is set when the Transport is
created, but additional host-to-backend mappings can be added with
the AddHostBackend method.

Transport is provided primarily to adapt existing code which uses
http.Client instances to work on Compute.  Using an http.Client
pulls in substantially more code, resulting in slower compile times
and larger binaries.  For this reason, we recommend new code use the
fsthttp.Request type and its Send() method directly whenever
possible.

## Fields

### Request

**Type:** `func(req *Request) error`

Request is an optional callback invoked before the request is
sent to the backend.  It allows callers to set
fsthttp.Request-specific fields, such as cache control options.

## Methods

### AddHostBackend

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

```go
func (t *Transport) AddHostBackend(host, backend string)
```

AddHostBackend adds a new host-to-backend mapping.  Multiple hosts
may be mapped to the same backend.

**Parameters**

- `host`: `string`
- `backend`: `string`

### RoundTrip

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

```go
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)
```

RoundTrip implements the http.RoundTripper interface.

The provided http.Request is adapted into an fsthttp.Request. If the
Transport's Request callback field is set, it is invoked so that the
fsthttp.Request can be modified before it is sent.  The request is
then sent to the backend matching the host in the URL.  The resulting
fsthttp.Response is adapted into an http.Response and returned.

The http.Response's Request field contains a context from which the
original fsthttp.Request and fsthttp.Response can be extracted using
fsthttp.RequestFromContext and fsthttp.ResponseFromContext.

**Parameters**

- `req`: `*http.Request`

**Returns**

`(*http.Response, error)`
