Transport
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
func(req *Request) errorRequest 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
View sourcefunc (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
View sourceRoundTrip 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