falcore: github.com/fitstar/falcore/filter Index | Files

package filter

import "github.com/fitstar/falcore/filter"

A collection of useful RequestFilters and ResponseFilters


Package Files

compression.go date_filter.go doc.go etag.go file_filter.go handler_filter.go string_body.go throttle.go upstream.go upstream_pool.go upstream_transport.go utilities.go


var DefaultTypes = []string{"text/plain", "text/html", "application/json", "text/xml"}

The default types to compress

func SplitHostPort Uses

func SplitHostPort(hostPort string, defaultPort int) (string, int)

DEPRECATED: use net.SplitHostPort

type CompressionFilter Uses

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 Uses

func NewCompressionFilter(types []string) *CompressionFilter

types is the mime types to compress. If none is specified, DefaultTypes is used.

func (*CompressionFilter) FilterResponse Uses

func (c *CompressionFilter) FilterResponse(request *falcore.Request, res *http.Response)

type DateFilter Uses

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 Uses

func (f *DateFilter) FilterResponse(request *falcore.Request, res *http.Response)

type EtagFilter Uses

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 Uses

func (f *EtagFilter) FilterResponse(request *falcore.Request, res *http.Response)

type FileFilter Uses

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 Uses

func (f *FileFilter) FilterRequest(req *falcore.Request) (res *http.Response)

type HandlerFilter Uses

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 Uses

func NewHandlerFilter(handler http.Handler) *HandlerFilter

func (*HandlerFilter) FilterRequest Uses

func (h *HandlerFilter) FilterRequest(req *falcore.Request) *http.Response

type StringBody Uses

type StringBody struct {
    BodyBuffer *bytes.Reader
    // contains filtered or unexported fields

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 Uses

func (sb *StringBody) Close() error

func (*StringBody) Read Uses

func (sb *StringBody) Read(b []byte) (n int, err error)

type StringBodyFilter Uses

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 Uses

func NewStringBodyFilter() *StringBodyFilter

func (*StringBodyFilter) FilterRequest Uses

func (sbf *StringBodyFilter) FilterRequest(request *falcore.Request) *http.Response

func (*StringBodyFilter) FilterResponse Uses

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 Uses

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 Uses

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 Uses

func NewThrottler(RPS int) *Throttler

func (*Throttler) FilterRequest Uses

func (t *Throttler) FilterRequest(req *falcore.Request) *http.Response

func (*Throttler) Pending Uses

func (t *Throttler) Pending() int64

Returns the number of requests waiting on the throttler

func (*Throttler) SetRPS Uses

func (t *Throttler) SetRPS(RPS int)

Change the throttling limit

func (*Throttler) StartReporter Uses

func (t *Throttler) StartReporter(name string, interval time.Duration)

Logs the number of pending requests at WARN level every :interval :name is included in log line Does not log if nothing is being throttled.

type Upstream Uses

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 Uses

func NewUpstream(transport *UpstreamTransport) *Upstream

func (*Upstream) FilterRequest Uses

func (u *Upstream) FilterRequest(request *falcore.Request) (res *http.Response)

func (*Upstream) MaxConcurrent Uses

func (u *Upstream) MaxConcurrent() int64

Returns the current maxconcurrent

func (*Upstream) QueueLength Uses

func (u *Upstream) QueueLength() int64

Returns the number of requests waiting on throttling

func (*Upstream) SetMaxConcurrent Uses

func (u *Upstream) SetMaxConcurrent(max int64)

Set the maximum number of concurrent requests to send to upstream Set to 0 (the default) to disable throttling.

type UpstreamEntry Uses

type UpstreamEntry struct {
    Upstream *Upstream
    Weight   int

type UpstreamPool Uses

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 Uses

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 Uses

func (up UpstreamPool) FilterRequest(req *falcore.Request) (res *http.Response)

func (UpstreamPool) LogStatus Uses

func (up UpstreamPool) LogStatus()

Logs the current status of the pool

func (UpstreamPool) Next Uses

func (up UpstreamPool) Next() *UpstreamEntry

func (UpstreamPool) Shutdown Uses

func (up UpstreamPool) Shutdown()

This should only be called if the upstream pool is no longer active or this may deadlock

type UpstreamTransport Uses

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 Uses

func NewUpstreamTransport(host string, port int, timeout time.Duration, transport *http.Transport) *UpstreamTransport

transport is optional. We will override Dial

Package filter imports 18 packages (graph) and is imported by 1 packages. Updated 2016-09-13. Refresh now. Tools for package owners.