fastly

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2023 License: Apache-2.0, BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package fastly provides access to the Compute@Edge hostcall ABI.

The TinyGo SDK is modeled in layers. Each layer has a single purpose. This package is the lowest layer, and it's singular purpose is to adapt each Compute@Edge hostcall to a function which is basically idiomatic Go.

In support of that purpose, the package defines a few types, e.g. HTTPBody, which model the modules of the hostcalls, and implement corresponding functions as methods on those types. Each hostcall should have a single corresponding Go method or function.

There are also helper types, like Values, which make it easier to interact with the hostcall ABI. But, in general, this package should be kept as small as possible, and all nontrivial work performed at the next layer up, e.g. package fsthttp.

This package is not and should not be user-accessible. All features, capabilities, etc. that should be accessible by users should be made available via separate packages that treat this package as a dependency.

Index

Constants

View Source
const (
	// DefaultMaxHeaderNameLen is the default header name length limit
	DefaultMaxHeaderNameLen = 8192
	// DefaultMaxHeaderValueLen is the default header value length limit
	DefaultMaxHeaderValueLen = 8192
	// DefaultMaxMethodLen is the default method length limit
	DefaultMaxMethodLen = 1024
	// DefaultMaxURLLen is the default URL length limit
	DefaultMaxURLLen = 8192
)

Variables

This section is empty.

Functions

func BodyDownstreamGet

func BodyDownstreamGet() (*HTTPRequest, *HTTPBody, error)

func DownstreamClientIPAddr

func DownstreamClientIPAddr() (net.IP, error)

func DownstreamTLSCipherOpenSSLName

func DownstreamTLSCipherOpenSSLName() (string, error)

func DownstreamTLSClientHello

func DownstreamTLSClientHello() ([]byte, error)

func DownstreamTLSProtocol

func DownstreamTLSProtocol() (string, error)

func GeoLookup

func GeoLookup(ip net.IP) ([]byte, error)

func GetOriginalHeaderCount

func GetOriginalHeaderCount() (int, error)

func ParseUserAgent

func ParseUserAgent(userAgent string) (family, major, minor, patch string, err error)

func PendingRequestSelect

func PendingRequestSelect(reqs ...*PendingRequest) (index int, done *PendingRequest, response *HTTPResponse, responseBody *HTTPBody, err error)

func PurgeSurrogateKey added in v0.1.4

func PurgeSurrogateKey(surrogateKey string, opts PurgeOptions) error

func RegisterDynamicBackend added in v0.1.5

func RegisterDynamicBackend(name string, target string, opts *BackendConfigOptions) error

Types

type AutoDecompressResponseOptions

type AutoDecompressResponseOptions struct {
	Gzip bool
}

AutoDecompressResponseOptions collects the auto decompress response options for the request. See the equivalent DecompressResponseOptions type in package fsthttp for more detailed descriptions of each field.

type BackendConfigOptions added in v0.1.5

type BackendConfigOptions struct {
	// contains filtered or unexported fields
}

func (*BackendConfigOptions) BetweenBytesTimeout added in v0.1.5

func (b *BackendConfigOptions) BetweenBytesTimeout(t time.Duration)

func (*BackendConfigOptions) CACert added in v0.1.5

func (b *BackendConfigOptions) CACert(caCert string)

func (*BackendConfigOptions) CertHostname added in v0.1.5

func (b *BackendConfigOptions) CertHostname(certHostname string)

func (*BackendConfigOptions) Ciphers added in v0.1.5

func (b *BackendConfigOptions) Ciphers(ciphers string)

func (*BackendConfigOptions) ConnectTimeout added in v0.1.5

func (b *BackendConfigOptions) ConnectTimeout(t time.Duration)

func (*BackendConfigOptions) FirstByteTimeout added in v0.1.5

func (b *BackendConfigOptions) FirstByteTimeout(t time.Duration)

func (*BackendConfigOptions) HostOverride added in v0.1.5

func (b *BackendConfigOptions) HostOverride(host string)

func (*BackendConfigOptions) SNIHostname added in v0.1.5

func (b *BackendConfigOptions) SNIHostname(sniHostname string)

func (*BackendConfigOptions) SSLMaxVersion added in v0.1.5

func (b *BackendConfigOptions) SSLMaxVersion(v TLSVersion)

func (*BackendConfigOptions) SSLMinVersion added in v0.1.5

func (b *BackendConfigOptions) SSLMinVersion(v TLSVersion)

func (*BackendConfigOptions) UseSSL added in v0.1.5

func (b *BackendConfigOptions) UseSSL(v bool)

type CacheEntry added in v0.1.4

type CacheEntry struct{}

func CacheLookup added in v0.1.4

func CacheLookup(key []byte, opts CacheLookupOptions) (*CacheEntry, error)

func CacheTransactionLookup added in v0.1.4

func CacheTransactionLookup(key []byte, opts CacheLookupOptions) (*CacheEntry, error)

func (*CacheEntry) Age added in v0.1.4

func (c *CacheEntry) Age() (time.Duration, error)

func (*CacheEntry) Body added in v0.1.4

func (c *CacheEntry) Body(opts CacheGetBodyOptions) (*HTTPBody, error)

func (*CacheEntry) Cancel added in v0.1.4

func (e *CacheEntry) Cancel() error

func (*CacheEntry) Close added in v0.1.4

func (c *CacheEntry) Close() error

func (*CacheEntry) Hits added in v0.1.4

func (c *CacheEntry) Hits() (uint64, error)

func (*CacheEntry) Insert added in v0.1.4

func (e *CacheEntry) Insert(opts CacheWriteOptions) (*HTTPBody, error)

func (*CacheEntry) InsertAndStreamBack added in v0.1.4

func (e *CacheEntry) InsertAndStreamBack(opts CacheWriteOptions) (*HTTPBody, *CacheEntry, error)

func (*CacheEntry) Length added in v0.1.4

func (c *CacheEntry) Length() (uint64, error)

func (*CacheEntry) MaxAge added in v0.1.4

func (c *CacheEntry) MaxAge() (time.Duration, error)

func (*CacheEntry) StaleWhileRevalidate added in v0.1.4

func (c *CacheEntry) StaleWhileRevalidate() (time.Duration, error)

func (*CacheEntry) State added in v0.1.4

func (c *CacheEntry) State() (CacheLookupState, error)

func (*CacheEntry) Update added in v0.1.4

func (e *CacheEntry) Update(opts CacheWriteOptions) error

func (*CacheEntry) UserMetadata added in v0.1.4

func (c *CacheEntry) UserMetadata() ([]byte, error)

type CacheGetBodyOptions added in v0.1.4

type CacheGetBodyOptions struct{}

func (*CacheGetBodyOptions) From added in v0.1.4

func (o *CacheGetBodyOptions) From(from uint64) error

func (*CacheGetBodyOptions) To added in v0.1.4

func (o *CacheGetBodyOptions) To(to uint64) error

type CacheLookupOptions added in v0.1.4

type CacheLookupOptions struct{}

func (*CacheLookupOptions) SetRequest added in v0.1.4

func (o *CacheLookupOptions) SetRequest(req *HTTPRequest) error

type CacheLookupState added in v0.1.4

type CacheLookupState prim.U32

witx:

;;; The status of this lookup (and potential transaction)
(typename $cache_lookup_state
    (flags (@witx repr u32)
        $found ;; a cached object was found
        $usable ;; the cached object is valid to use (implies $found)
        $stale ;; the cached object is stale (but may or may not be valid to use)
        $must_insert_or_update ;; this client is requested to insert or revalidate an object
    )
)
const (
	CacheLookupStateFound              CacheLookupState = 0b0000_0001 // $found
	CacheLookupStateUsable             CacheLookupState = 0b0000_0010 // $usable
	CacheLookupStateStale              CacheLookupState = 0b0000_0100 // $stale
	CacheLookupStateMustInsertOrUpdate CacheLookupState = 0b0000_1000 // $must_insert_or_update
)

type CacheOverrideOptions

type CacheOverrideOptions struct {
	Pass                 bool
	PCI                  bool
	TTL                  uint32 // seconds
	StaleWhileRevalidate uint32 // seconds
	SurrogateKey         string
}

CacheOverrideOptions collects specific, caching-related options for outbound requests. See the equivalent CacheOverrideOptions type in package fsthttp for more detailed descriptions of each field.

type CacheWriteOptions added in v0.1.4

type CacheWriteOptions struct{}

func (*CacheWriteOptions) ContentLength added in v0.1.4

func (o *CacheWriteOptions) ContentLength(v uint64) error

func (*CacheWriteOptions) InitialAge added in v0.1.4

func (o *CacheWriteOptions) InitialAge(v time.Duration) error

func (*CacheWriteOptions) MaxAge added in v0.1.4

func (o *CacheWriteOptions) MaxAge(v time.Duration) error

func (*CacheWriteOptions) SensitiveData added in v0.1.4

func (o *CacheWriteOptions) SensitiveData(v bool) error

func (*CacheWriteOptions) SetRequest added in v0.1.4

func (o *CacheWriteOptions) SetRequest(req *HTTPRequest) error

func (*CacheWriteOptions) StaleWhileRevalidate added in v0.1.4

func (o *CacheWriteOptions) StaleWhileRevalidate(v time.Duration) error

func (*CacheWriteOptions) SurrogateKeys added in v0.1.4

func (o *CacheWriteOptions) SurrogateKeys(v []string) error

func (*CacheWriteOptions) UserMetadata added in v0.1.4

func (o *CacheWriteOptions) UserMetadata(v []byte) error

func (*CacheWriteOptions) Vary added in v0.1.4

func (o *CacheWriteOptions) Vary(v []string) error

type Dictionary

type Dictionary struct{}

func OpenDictionary

func OpenDictionary(name string) (*Dictionary, error)

func (*Dictionary) Get

func (d *Dictionary) Get(key string) (string, error)

type FastlyError

type FastlyError struct {
	Status FastlyStatus
}

FastlyError decorates error-class FastlyStatus values and implements the error interface.

Note that TinyGo currently doesn't support errors.As. Callers can use the IsFastlyError helper instead.

func (FastlyError) Error

func (e FastlyError) Error() string

Error implements the error interface.

type FastlyStatus

type FastlyStatus uint32

FastlyStatus models a response status enum.

const (
	// FastlyStatusOK maps to $fastly_status $ok.
	// TODO(pb): is this the only non-error status?
	FastlyStatusOK FastlyStatus = 0

	// FastlyStatusError maps to $fastly_status $error.
	FastlyStatusError FastlyStatus = 1

	// FastlyStatusInval maps to $fastly_status $inval.
	FastlyStatusInval FastlyStatus = 2

	// FastlyStatusBadf maps to $fastly_status $badf.
	FastlyStatusBadf FastlyStatus = 3

	// FastlyStatusBufLen maps to $fastly_status $buflen.
	FastlyStatusBufLen FastlyStatus = 4

	// FastlyStatusUnsupported maps to $fastly_status $unsupported.
	FastlyStatusUnsupported FastlyStatus = 5

	// FastlyStatusBadAlign maps to $fastly_status $badalign.
	FastlyStatusBadAlign FastlyStatus = 6

	// FastlyStatusHTTPInvalid maps to $fastly_status $httpinvalid.
	FastlyStatusHTTPInvalid FastlyStatus = 7

	// FastlyStatusHTTPUser maps to $fastly_status $httpuser.
	FastlyStatusHTTPUser FastlyStatus = 8

	// FastlyStatusHTTPIncomplete maps to $fastly_status $httpincomplete.
	FastlyStatusHTTPIncomplete FastlyStatus = 9

	// FastlyStatusNone maps to $fastly_status $none.
	FastlyStatusNone FastlyStatus = 10

	// FastlyStatusHTTPHeadTooLarge maps to $fastly_status $httpheadtoolarge.
	FastlyStatusHTTPHeadTooLarge FastlyStatus = 11

	// FastlyStatusHTTPInvalidStatus maps to $fastly_status $httpinvalidstatus.
	FastlyStatusHTTPInvalidStatus FastlyStatus = 12

	// FastlyStatusLimitExceeded maps to $fastly_status $limitexceeded.
	FastlyStatusLimitExceeded FastlyStatus = 13
)

func IsFastlyError

func IsFastlyError(err error) (FastlyStatus, bool)

IsFastlyError detects and unwraps a FastlyError to its component parts.

func (FastlyStatus) String

func (s FastlyStatus) String() string

String implements fmt.Stringer.

type HTTPBody

type HTTPBody struct{}

func CacheInsert added in v0.1.4

func CacheInsert(key []byte, opts CacheWriteOptions) (*HTTPBody, error)

func NewHTTPBody

func NewHTTPBody() (*HTTPBody, error)

func (*HTTPBody) Abandon added in v0.1.4

func (b *HTTPBody) Abandon() error

func (*HTTPBody) Append

func (b *HTTPBody) Append(other *HTTPBody) error

func (*HTTPBody) Close

func (b *HTTPBody) Close() error

func (*HTTPBody) Read

func (b *HTTPBody) Read(p []byte) (int, error)

func (*HTTPBody) Write

func (b *HTTPBody) Write(p []byte) (n int, err error)

type HTTPRequest

type HTTPRequest struct{}

func NewHTTPRequest

func NewHTTPRequest() (*HTTPRequest, error)

func (*HTTPRequest) AppendHeader

func (r *HTTPRequest) AppendHeader(name, value string) error

func (*HTTPRequest) GetHeaderNames

func (r *HTTPRequest) GetHeaderNames(maxHeaderNameLen int) *Values

func (*HTTPRequest) GetHeaderValue

func (r *HTTPRequest) GetHeaderValue(name string, maxHeaderValueLen int) (string, error)

func (*HTTPRequest) GetHeaderValues

func (r *HTTPRequest) GetHeaderValues(name string, maxHeaderValueLen int) *Values

func (*HTTPRequest) GetMethod

func (r *HTTPRequest) GetMethod(maxMethodLen int) (string, error)

func (*HTTPRequest) GetURI

func (r *HTTPRequest) GetURI(maxURLLen int) (string, error)

func (*HTTPRequest) GetVersion

func (r *HTTPRequest) GetVersion() (proto string, major, minor int, err error)

func (*HTTPRequest) InsertHeader

func (r *HTTPRequest) InsertHeader(name, value string) error

func (*HTTPRequest) RemoveHeader

func (r *HTTPRequest) RemoveHeader(name string) error

func (*HTTPRequest) Send

func (r *HTTPRequest) Send(requestBody *HTTPBody, backend string) (response *HTTPResponse, responseBody *HTTPBody, err error)

func (*HTTPRequest) SendAsync

func (r *HTTPRequest) SendAsync(requestBody *HTTPBody, backend string) (*PendingRequest, error)

func (*HTTPRequest) SendAsyncStreaming

func (r *HTTPRequest) SendAsyncStreaming(requestBody *HTTPBody, backend string) (*PendingRequest, error)

func (*HTTPRequest) SetAutoDecompressResponse

func (r *HTTPRequest) SetAutoDecompressResponse(options AutoDecompressResponseOptions) error

func (*HTTPRequest) SetCacheOverride

func (r *HTTPRequest) SetCacheOverride(options CacheOverrideOptions) error

func (*HTTPRequest) SetFramingHeadersMode

func (r *HTTPRequest) SetFramingHeadersMode(manual bool) error

func (*HTTPRequest) SetHeaderValues

func (r *HTTPRequest) SetHeaderValues(name string, values []string) error

func (*HTTPRequest) SetMethod

func (r *HTTPRequest) SetMethod(method string) error

func (*HTTPRequest) SetURI

func (r *HTTPRequest) SetURI(uri string) error

func (*HTTPRequest) SetVersion

func (r *HTTPRequest) SetVersion(v HTTPVersion) error

type HTTPResponse

type HTTPResponse struct{}

func NewHTTPResponse

func NewHTTPResponse() (*HTTPResponse, error)

func (*HTTPResponse) AppendHeader

func (r *HTTPResponse) AppendHeader(name, value string) error

func (*HTTPResponse) GetHeaderNames

func (r *HTTPResponse) GetHeaderNames(maxHeaderNameLen int) *Values

func (*HTTPResponse) GetHeaderValue

func (r *HTTPResponse) GetHeaderValue(name string, maxHeaderValueLen int) (string, error)

func (*HTTPResponse) GetHeaderValues

func (r *HTTPResponse) GetHeaderValues(name string, maxHeaderValueLen int) *Values

func (*HTTPResponse) GetStatusCode

func (r *HTTPResponse) GetStatusCode() (int, error)

func (*HTTPResponse) GetVersion

func (r *HTTPResponse) GetVersion() (proto string, major, minor int, err error)

func (*HTTPResponse) InsertHeader

func (r *HTTPResponse) InsertHeader(name, value string) error

func (*HTTPResponse) RemoveHeader

func (r *HTTPResponse) RemoveHeader(name string) error

func (*HTTPResponse) SendDownstream

func (r *HTTPResponse) SendDownstream(responseBody *HTTPBody, stream bool) error

func (*HTTPResponse) SetFramingHeadersMode

func (r *HTTPResponse) SetFramingHeadersMode(manual bool) error

func (*HTTPResponse) SetHeaderValues

func (r *HTTPResponse) SetHeaderValues(name string, values []string) error

func (*HTTPResponse) SetStatusCode

func (r *HTTPResponse) SetStatusCode(code int) error

func (*HTTPResponse) SetVersion

func (r *HTTPResponse) SetVersion(v HTTPVersion) error

type HTTPVersion

type HTTPVersion uint32

HTTPVersion describes an HTTP protocol version.

const (
	// HTTPVersionHTTP09 describes HTTP/0.9.
	HTTPVersionHTTP09 HTTPVersion = 0

	// HTTPVersionHTTP10 describes HTTP/1.0.
	HTTPVersionHTTP10 HTTPVersion = 1

	// HTTPVersionHTTP11 describes HTTP/1.1.
	HTTPVersionHTTP11 HTTPVersion = 2

	// HTTPVersionH2 describes HTTP/2.
	HTTPVersionH2 HTTPVersion = 3

	// HTTPVersionH3 describes HTTP/3.
	HTTPVersionH3 HTTPVersion = 4
)

type KVStore added in v0.1.3

type KVStore struct{}

func OpenKVStore added in v0.1.3

func OpenKVStore(name string) (*KVStore, error)

func (*KVStore) Insert added in v0.1.3

func (o *KVStore) Insert(key string, value io.Reader) error

func (*KVStore) Lookup added in v0.1.3

func (o *KVStore) Lookup(key string) (io.Reader, error)

type LogEndpoint

type LogEndpoint struct{}

func GetLogEndpoint

func GetLogEndpoint(name string) (*LogEndpoint, error)

func (*LogEndpoint) Write

func (e *LogEndpoint) Write(p []byte) (n int, err error)

type PendingRequest

type PendingRequest struct{}

func (*PendingRequest) Poll

func (r *PendingRequest) Poll() (done bool, response *HTTPResponse, responseBody *HTTPBody, err error)

func (*PendingRequest) Wait

func (r *PendingRequest) Wait() (response *HTTPResponse, responseBody *HTTPBody, err error)

type PurgeOptions added in v0.1.4

type PurgeOptions struct{}

func (*PurgeOptions) SoftPurge added in v0.1.4

func (o *PurgeOptions) SoftPurge(v bool) error

type Secret added in v0.1.2

type Secret struct{}

func (*Secret) Plaintext added in v0.1.2

func (s *Secret) Plaintext() ([]byte, error)

type SecretStore added in v0.1.2

type SecretStore struct{}

func OpenSecretStore added in v0.1.2

func OpenSecretStore(name string) (*SecretStore, error)

func (*SecretStore) Get added in v0.1.2

func (s *SecretStore) Get(name string) (*Secret, error)

type TLSVersion added in v0.1.5

type TLSVersion prim.U32

witx:

(typename $tls_version
    (enum (@witx tag u32)
      $tls_1
      $tls_1_1
      $tls_1_2
      $tls_1_3))
const (
	TLSVersion1_0 TLSVersion = 0
	TLSVersion1_1 TLSVersion = 1
	TLSVersion1_2 TLSVersion = 2
	TLSVersion1_3 TLSVersion = 3
)

type Values

type Values struct {
	// contains filtered or unexported fields
}

Values is the result of a multi-value hostcall. It offers an iterator API similar to bufio.Scanner or sql.Rows.

func GetOriginalHeaderNames

func GetOriginalHeaderNames() *Values

func (*Values) Bytes

func (v *Values) Bytes() []byte

Bytes returns the most recent value generated by a call to Next. The underlying array may point to data that will be overwritten by a subsequent call to Next. Bytes performs no allocation.

func (*Values) Err

func (v *Values) Err() error

Err returns the error, if any, that was encountered during iteration.

func (*Values) Next

func (v *Values) Next() bool

Next prepares the next value for reading with the Bytes method. It returns true on success, or false if there are no more values, or an error occurred. Err should be called to distinguish between those two cases. Every call to Bytes, even the first one, must be preceded by a call to Next.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL