Documentation
¶
Overview ¶
A collection of useful RequestFilters and ResponseFilters
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultTypes = []string{"text/plain", "text/html", "application/json", "text/xml"}
The default types to compress
Functions ¶
Types ¶
type CompressionFilter ¶
type CompressionFilter struct {
// contains filtered or unexported fields
}
A ResponseFilter that performs compression when compression is available and the content isn't already compressed
func NewCompressionFilter ¶
func NewCompressionFilter(types []string) *CompressionFilter
types is the mime types to compress. If none is specified, DefaultTypes is used.
func (*CompressionFilter) FilterResponse ¶
func (c *CompressionFilter) FilterResponse(request *falcore.Request, res *http.Response)
type DateFilter ¶
type DateFilter struct { }
If Date header is non-existent in the response, this filter will automatically set it to the current date
func (*DateFilter) FilterResponse ¶
func (f *DateFilter) FilterResponse(request *falcore.Request, res *http.Response)
type EtagFilter ¶
type EtagFilter struct { }
EtagFilter is a falcore.ResponseFilter that matches the response's Etag header against the request's If-None-Match header. If they match, the filter will return a '304 Not Modifed' status and no body.
Ideally, Etag filtering is performed as soon as possible as you may be able to skip generating the response body at all. Even as a last step, you will see a significant benefit if clients are well behaved.
func (*EtagFilter) FilterResponse ¶
func (f *EtagFilter) FilterResponse(request *falcore.Request, res *http.Response)
type FileFilter ¶
type FileFilter struct { // File system base path for serving files BasePath string // Prefix in URL path PathPrefix string // File to look for if path is a directory DirectoryIndex string }
A falcore RequestFilter for serving static files from the filesystem. This filter returns nil if the file is not found or is outside of scope.
func (*FileFilter) FilterRequest ¶
func (f *FileFilter) FilterRequest(req *falcore.Request) (res *http.Response)
type HandlerFilter ¶
type HandlerFilter struct {
// contains filtered or unexported fields
}
Wraps an http.Handler in a falcore.RequestFilter. This allows for compatibility with existing handlers built for the standard library's http server. This will always return a response due to the requirements of the http.Handler interface so it should be placed at the end of the Upstream pipeline.
func NewHandlerFilter ¶
func NewHandlerFilter(handler http.Handler) *HandlerFilter
func (*HandlerFilter) FilterRequest ¶
func (h *HandlerFilter) FilterRequest(req *falcore.Request) *http.Response
type StringBody ¶
Keeps the body of a request in a string so it can be re-read at each stage of the pipeline implements io.ReadCloser to match http.Request.Body
func (*StringBody) Close ¶
func (sb *StringBody) Close() error
type StringBodyFilter ¶
type StringBodyFilter struct {
// contains filtered or unexported fields
}
Injests the body of the request into a buffer so it can be read more than once.
func NewStringBodyFilter ¶
func NewStringBodyFilter() *StringBodyFilter
func (*StringBodyFilter) FilterRequest ¶
func (sbf *StringBodyFilter) FilterRequest(request *falcore.Request) *http.Response
func (*StringBodyFilter) FilterResponse ¶
func (sbf *StringBodyFilter) FilterResponse(request *falcore.Request, res *http.Response)
Insert this in the response pipeline to return the buffer pool for the request body If there is an appropriate place in your flow, you can call ReturnBuffer explicitly
func (*StringBodyFilter) ReturnBuffer ¶
func (sbf *StringBodyFilter) ReturnBuffer(request *falcore.Request)
Returns a buffer used in the FilterRequest stage to a buffer pool this speeds up this filter significantly by reusing buffers
type Throttler ¶
type Throttler struct { Condition func(req *falcore.Request) bool // If this is set, and returns false, the request will not be throttled // contains filtered or unexported fields }
Throttles incomming requests at a maximum number of requests per second. Pending requests will just wait in a queue.
func NewThrottler ¶
func (*Throttler) FilterRequest ¶
type Upstream ¶
type Upstream struct { // Name, if set, is used in logging and request stats Name string Transport *UpstreamTransport // Will ignore https on the incoming request and always upstream http ForceHttp bool // Ping URL Path-only for checking upness PingPath string // contains filtered or unexported fields }
Proxies the request through another server. Can be used in conjunction with the UpstreamPool to load balance traffic across several servers.
func NewUpstream ¶
func NewUpstream(transport *UpstreamTransport) *Upstream
func (*Upstream) FilterRequest ¶
func (*Upstream) MaxConcurrent ¶
Returns the current maxconcurrent
func (*Upstream) QueueLength ¶
Returns the number of requests waiting on throttling
func (*Upstream) SetMaxConcurrent ¶
Set the maximum number of concurrent requests to send to upstream Set to 0 (the default) to disable throttling.
type UpstreamEntry ¶
type UpstreamPool ¶
type UpstreamPool struct { Name string // contains filtered or unexported fields }
An UpstreamPool is a list of upstream servers which are considered functionally equivalent. The pool will round-robin the requests to the servers.
func NewUpstreamPool ¶
func NewUpstreamPool(name string, upstreams []*UpstreamEntry) *UpstreamPool
The config consists of a map of the servers in the pool in the format host_or_ip:port where port is optional and defaults to 80. The map value is an int with the weight only 0 and 1 are supported weights (0 disables a server and 1 enables it)
func (UpstreamPool) FilterRequest ¶
func (up UpstreamPool) FilterRequest(req *falcore.Request) (res *http.Response)
func (UpstreamPool) LogStatus ¶
func (up UpstreamPool) LogStatus()
Logs the current status of the pool
func (UpstreamPool) Next ¶
func (up UpstreamPool) Next() *UpstreamEntry
func (UpstreamPool) Shutdown ¶
func (up UpstreamPool) Shutdown()
This should only be called if the upstream pool is no longer active or this may deadlock
type UpstreamTransport ¶
type UpstreamTransport struct { DNSCacheDuration time.Duration // contains filtered or unexported fields }
Holds all the information about how to lookup and connect to an upstream.
func NewUpstreamTransport ¶
func NewUpstreamTransport(host string, port int, timeout time.Duration, transport *http.Transport) *UpstreamTransport
transport is optional. We will override Dial