fsthttp
github.com/fastly/compute-sdk-go/fsthttp
Package fsthttp provides HTTP functionality for Fastly's Compute environment.
A Compute program can be thought of as an HTTP request handler. Each execution is triggered by an incoming request from a client, and is expected to respond to that request before terminating. The Serve function provides a Handler-style interface to that Request and its ResponseWriter.
The types in this package are similar to, but not the same as, corresponding types in the standard library's package net/http. Refer to the documentation for important caveats about usage.
Structs
| Backend | Backend is a fastly backend |
| BackendHealthcheckOptions | |
| BackendOptions | BackendOption is a builder for the configuration of a dynamic backend. |
| BotDetectionResult | |
| CacheOptions | CacheOptions control caching behavior for outgoing requests. |
| CandidateResponse | CandidateResponse is a response from a backend that is a candidate for caching. |
| Cookie | A Cookie represents an HTTP cookie as sent in the Set-Cookie header of an HTTP response or the Cookie header of an HTTP request. |
| DecompressResponseOptions | DecompressResponseOptions control the auto decompress response behaviour. |
| FastlyMeta | FastlyMeta holds various Fastly-specific metadata for a request. |
| InspectOptions | |
| InspectResponse | |
| Limitsdeprecated | Limits handles HTTP limits. |
| Request | 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. |
| Response | Response to an outgoing HTTP request made by this server. |
| ResVPNProxyResult | ResVPNProxyResult represents additional IP Proxy and VPN Intelligence data for a request. |
| ServeManyOptions | ServeManyOptions controls the exit conditions for ServeMany. Note that Compute might terminate the request hander earlier. |
| TLSClientCertificateInfo | |
| TLSInfo | TLSInfo collects TLS-related metadata for incoming requests. All fields are ignored for outgoing requests. |
| Transport | Transport is an http.RoundTripper implementation for backend requests on Compute. |
Interfaces
| Handler | Handler describes anything which can handle, or respond to, an HTTP request. It has the same semantics as net/http.Handler, but operates on the Request and ResponseWriter types defined in this package. |
| ResponseWriter | ResponseWriter is used to respond to client requests. |
Enums
| BackendHealth | |
| NGWAFVerdict | |
| SameSite | SameSite allows a server to define a cookie attribute making it impossible for the browser to send this cookie along with cross-site requests. The main goal is to mitigate the risk of cross-origin information leakage, and provide some protection against cross-site request forgery attacks. |
| TLSVersion |
Type aliases
| BotCategory | |
| ClientCertificateVerifyResult | |
| HandlerFunc | HandlerFunc adapts a function to a Handler. |
| Header | Header represents the key-value pairs in a set of HTTP headers. Unlike net/http, keys are canonicalized to their lowercase form. |
| SendError | SendError provides detailed information about backend request failures. |
| SendErrorTag |
Functions
| Adapt | Adapt allows an http.Handler to be used as an fsthttp.Handler. |
| BackendFromName | |
| CanonicalHeaderKey | CanonicalHeaderKey returns the canonical format of the header key s. The canonicalization converts the first letter and any letter following a hyphen to upper case; the rest are converted to lowercase. For example, the canonical key for "accept-encoding" is "Accept-Encoding". If s contains a space or invalid header field bytes, it is returned without modifications. |
| Error | Error replies to the request with the specified error message and HTTP code. It does not otherwise end the request; the caller should ensure no further writes are done to w. The error message should be plain text. |
| NewBackendHealthcheck | |
| NewBackendOptions | |
| NewHeader | NewHeader returns an initialized and empty set of headers. |
| NewRequest | NewRequest constructs an outgoing request with the given HTTP method, URI, and body. The URI is parsed via url.Parse. |
| NewTransport | NewTransport creates a new Transport instance with the given default backend. Any request made to a host not explicitly mapped to a backend using the AddHostBackend method will be sent to the default backend. |
| NotFound | NotFound replies to the request with an HTTP 404 not found error. |
| RegisterDynamicBackend | RegisterDynamicBackend registers a new dynamic backend. |
| RequestFromContext | RequestFromContext returns the fsthttp.Request associated with the context, if any. |
| ResponseFromContext | ResponseFromContext returns the fsthttp.Response associated with the context, if any. |
| ResponseWriterFromContext | ResponseWriterFromContext returns the fsthttp.ResponseWriter associated with the context, if any. |
| Serve | Serve calls h, providing it with a context that will be canceled when Serve returns, a Request representing the incoming client request that initiated this execution, and a ResponseWriter that can be used to respond to that request. Serve will ensure the ResponseWriter has been closed before returning, and so should only be called once per execution. |
| ServeFunc | ServeFunc is sugar for Serve(HandlerFunc(f)). |
| ServeMany | ServeMany allows a single Compute instance to handle multiple requests. |
| SetCookie | SetCookie adds a Set-Cookie header to the provided ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped. |
| StatusText | StatusText returns a text for the HTTP status code. It returns the empty string if the code is unknown. |
Constants
Default: 1
Constants for dynamic backend health status
Default: 2
Constants for dynamic backend health status
Default: 0
Constants for dynamic backend health status
Default: fastly.BotCategoryAICrawler
BotCategoryAICrawler is for crawlers used for training AIs and LLMs, generally used for building AI models or indexes.
Default: fastly.BotCategoryAIFetcher
BotCategoryAIFetcher is for fetchers used by AIs and LLMs for enriching results in response to a user query.
Default: fastly.BotCategoryAccessibility
BotCategoryAccessibility is for tools that make content accessible (e.g., screen readers).
Default: fastly.BotCategoryContentFetcher
BotCategoryContentFetcher is for tools that extract content from websites to be used elsewhere.
Default: fastly.BotCategoryHeadless
BotCategoryHeadless is for a request that is suspected of being a headless bot.
Default: fastly.BotCategoryMonitoringSiteTools
BotCategoryMonitoringSiteTools is for tools that access your website to monitor things like performance, uptime, and proving domain control.
Default: fastly.BotCategoryNone
BotCategoryNone indicates bot detection was not executed, or no bot was detected.
Default: fastly.BotCategoryOnlineMarketing
BotCategoryOnlineMarketing is for crawlers from online marketing platforms (e.g., Facebook, Pinterest).
Default: fastly.BotCategoryPagePreview
BotCategoryPagePreview is for tools that access your website to show a preview of the page in other online services and social media platforms.
Default: fastly.BotCategoryPlatformIntegrations
BotCategoryPlatformIntegrations is for integration with other platforms by accessing the website's API, notably Webhooks.
Default: fastly.BotCategoryResearch
BotCategoryResearch is for commercial and academic tools that collect and analyze data for research purposes.
Default: fastly.BotCategorySearchEngineCrawler
BotCategorySearchEngineCrawler is for crawlers that index your website for search engines.
Default: fastly.BotCategorySearchEngineSpecialization
BotCategorySearchEngineSpecialization is for tools that support search engine optimization tasks (e.g., link analysis, ranking).
Default: fastly.BotCategorySecurityTools
BotCategorySecurityTools is for security analysis tools that inspect your website for vulnerabilities, misconfigurations and other security features.
Default: fastly.BotCategorySuspected
BotCategorySuspected is for a suspected bot.
Default: fastly.BotCategoryUnknown
BotCategoryUnknown indicates the detected bot belongs to a category not recognized by this SDK version.
Default: fastly.ClientCertificateVerifyResultBadCertificate
ClientCertificateVerifyResultBadCertificate means the certificate is corrupt (e.g., the certificate signatures do not verify correctly).
ClientCertificateVerifyResultCertificateExpired
fastly.ClientCertificateVerifyResultread-onlyView sourceDefault: fastly.ClientCertificateVerifyResultCertificateExpired
ClientCertificateVerifyResultCertificateExpired means the client certificate has expired or is not currently valid.
ClientCertificateVerifyResultCertificateMissing
fastly.ClientCertificateVerifyResultread-onlyView sourceDefault: fastly.ClientCertificateVerifyResultCertificateMissing
ClientCertificateVerifyResultCertificateMissing means the client did not provide a certificate during the handshake.
ClientCertificateVerifyResultCertificateRevoked
fastly.ClientCertificateVerifyResultread-onlyView sourceDefault: fastly.ClientCertificateVerifyResultCertificateRevoked
ClientCertificateVerifyResultCertificateRevoked means the client certificate is revoked by its signer.
ClientCertificateVerifyResultCertificateUnknown
fastly.ClientCertificateVerifyResultread-onlyView sourceDefault: fastly.ClientCertificateVerifyResultCertificateUnknown
ClientCertificateVerifyResultCertificateUnknown means the client certificate was received, but some other (unspecified) issue arose in processing the certificate, rendering it unacceptable.
Default: fastly.ClientCertificateVerifyResultOK
ClientCertificateVerifyResultOK indicates that client certificate verified successfully.
Default: fastly.ClientCertificateVerifyResultUnknownCA
ClientCertificateVerifyResultUnknownCA means the valid certificate chain or partial chain was received, but the certificate was not accepted because the CA certificate could not be located or could not be matched with a known trust anchor.
Default: "allow"
Default: "block"
Default: "unauthorized"
Default: "CONNECT"
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
Default: "DELETE"
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
Default: "GET"
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
Default: "HEAD"
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
Default: "OPTIONS"
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
Default: "POST"
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
Default: "PUT"
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
Default: "TRACE"
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
Default: iota + 1
Default: 2
Default: 4
Default: 3
Default: fastly.SendErrorDetailTagConnectionLimitReached
SendErrorConnectionLimitReached indicates the system is configured to limit the number of connections it has to the backend, and that limit has been reached.
Default: fastly.SendErrorDetailTagConnectionRefused
SendErrorConnectionRefused indicates the system's connection to the backend was refused.
Default: fastly.SendErrorDetailTagConnectionTerminated
SendErrorConnectionTerminated indicates the system's connection to the backend was closed before a complete response was received.
Default: fastly.SendErrorDetailTagConnectionTimeout
SendErrorConnectionTimeout indicates the system's attempt to open a connection to the backend timed out.
Default: fastly.SendErrorDetailTagDNSError
SendErrorDNSError indicates the system encountered a DNS error when trying to find an IP address for the backend hostname. Use DNSErrorRCode() and DNSErrorInfoCode() to get additional details.
Default: fastly.SendErrorDetailTagDNSTimeout
SendErrorDNSTimeout indicates the system encountered a timeout when trying to find an IP address for the backend hostname.
Default: fastly.SendErrorDetailTagDestinationIPUnroutable
SendErrorDestinationIPUnroutable indicates the system cannot find a route to the next-hop IP address.
Default: fastly.SendErrorDetailTagDestinationNotFound
SendErrorDestinationNotFound indicates the system cannot determine which backend to use, or the specified backend was invalid.
Default: fastly.SendErrorDetailTagDestinationUnavailable
SendErrorDestinationUnavailable indicates the system considers the backend to be unavailable (e.g., recent attempts to communicate with it may have failed, or a health check may indicate that it is down).
Default: fastly.SendErrorDetailTagHTTPIncompleteResponse
SendErrorHTTPIncompleteResponse indicates the system received an incomplete response to the request from the backend.
Default: fastly.SendErrorDetailTagHTTPProtocolError
SendErrorHTTPProtocolError indicates the system encountered an HTTP protocol error when communicating with the backend. This error will only be used when a more specific one is not defined.
Default: fastly.SendErrorDetailTagHTTPRequestCacheKeyInvalid
SendErrorHTTPRequestCacheKeyInvalid indicates an invalid Fastly cache key was provided for the request.
Default: fastly.SendErrorDetailTagHTTPRequestURIInvalid
SendErrorHTTPRequestURIInvalid indicates an invalid URI was provided for the request.
Default: fastly.SendErrorDetailTagHTTPResponseBodyTooLarge
SendErrorHTTPResponseBodyTooLarge indicates the system received a response to the request whose body was considered too large. For specific limits, visit the Compute resource limits documentation.
Default: fastly.SendErrorDetailTagHTTPResponseHeaderSectionTooLarge
SendErrorHTTPResponseHeaderSectionTooLarge indicates the system received a response to the request whose header section was considered too large. For specific limits, visit the Compute resource limits documentation.
Default: fastly.SendErrorDetailTagHTTPResponseStatusInvalid
SendErrorHTTPResponseStatusInvalid indicates the system received a response to the request whose status code or reason phrase was invalid.
Default: fastly.SendErrorDetailTagHTTPResponseTimeout
SendErrorHTTPResponseTimeout indicates the system reached a configured time limit waiting for the complete response. The limit is configured on the backend.
Default: fastly.SendErrorDetailTagHTTPUpgradeFailed
SendErrorHTTPUpgradeFailed indicates the process of negotiating an upgrade of the HTTP version between the system and the backend failed.
Default: fastly.SendErrorDetailTagInternalError
SendErrorInternalError indicates the system encountered an unexpected internal error.
Default: fastly.SendErrorDetailTagTLSAlertReceived
SendErrorTLSAlertReceived indicates the system received a TLS alert from the backend. Use TLSAlertID() and TLSAlertDescription() to get the specific alert.
Default: fastly.SendErrorDetailTagTLSCertificateError
SendErrorTLSCertificateError indicates the system encountered an error when verifying the certificate presented by the backend.
Default: fastly.SendErrorDetailTagTLSConfigurationError
SendErrorTLSConfigurationError indicates the system encountered an error with the backend TLS configuration.
Default: fastly.SendErrorDetailTagTLSProtocolError
SendErrorTLSProtocolError indicates the system encountered a TLS error when communicating with the backend, either during the handshake or afterwards.
Default: 0
Constants for dynamic backend TLS configuration
Default: 1
Constants for dynamic backend TLS configuration
Default: 2
Constants for dynamic backend TLS configuration
Default: 3
Constants for dynamic backend TLS configuration
Default: "Mon, 02 Jan 2006 15:04:05 GMT"
TimeFormat is the time format to use when generating times in HTTP headers. It is like time.RFC1123 but hard-codes GMT as the time zone. The time being formatted must be in UTC for Format to generate the correct format.
For parsing this time format, see ParseTime.
Default: "Trailer:"
TrailerPrefix is a magic prefix for ResponseWriter.Header map keys that, if present, signals that the map entry is actually for the response trailers, and not the response headers. The prefix is stripped after the ServeHTTP call finishes and the values are sent in the trailers.
This mechanism is intended only for trailers that are not known prior to the headers being written. If the set of trailers is fixed or known before the header is written, the normal Go trailers mechanism is preferred.
Variables
Default: errors.New("backend name already in use")
ErrBackendNameInUse indicates the backend name is already in use.
Default: errors.New("backend not found")
ErrBackendNotFound indicates the provided backend was not found.
Default: errors.New("fsthttp: caching not supported")
ErrCachingNotSupported is returned by Send() if the requested caching type (host or guest) is not supported by the request configuration or runtime.
Default: errors.New("connection has been closed")
ErrClosed is returned when attempting to write to a ResponseWriter whose network connection has been closed.
Default: errors.New("dynamic backends not supported for this service")
ErrDynamicBackendDisallowed indicates the service is not allowed to create dynamic backends.
Default: errors.New("fanout or websockets are not enabled on this service; please contact support for help")
Default: errors.New("handoff not supported on this request")
Default: errors.New("invalid HTTP status code")
ErrInvalidStatusCode is returned when attempting to write a resposne with an invalid HTTP status code.
Default: errors.New("fsthttp: named cookie not present")
ErrNoCookie is returned by Request's Cookie method when a cookie is not found.
Default: errors.New("error during request collapse")
Default: errors.New("trailers not available")
Default: errors.New("unexpected error")
ErrUnexpected indicates an unexpected error occurred.
RequestLimits are the limits for the components of an HTTP request.
ResponseLimits are the limits for the components of an HTTP response.