web

package
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2018 License: Apache-2.0 Imports: 11 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRequestTime

func AddRequestTime(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)

AddRequestTime is a web context that adds the current time to the request's context

func AddTime

func AddTime(ctx context.Context, now time.Time) context.Context

AddTime will add now to the context's time. You can get now later with RequestTime

func InvalidContentType

func InvalidContentType(w http.ResponseWriter, r *http.Request)

InvalidContentType is a HTTP handler helper to signal that the content type header is wrong

func RequestTime

func RequestTime(ctx context.Context) time.Time

RequestTime looks at the context to return the time added with AddTime

func ToHTTP

func ToHTTP(ctx context.Context, c ContextHandler) http.Handler

ToHTTP converts a ContextHandler into a http.Handler by calling c() with the added ctx

Types

type BucketRequestCounter

type BucketRequestCounter struct {
	ActiveConnections int64
	Bucket            *sfxclient.RollingBucket
}

BucketRequestCounter is a negroni handler that tracks connection stats including p99/etc. It's, ideally, an improvment over reqcounter.go

func (*BucketRequestCounter) Datapoints

func (m *BucketRequestCounter) Datapoints() []*datapoint.Datapoint

Datapoints returns active connections plus wrapped bucket stats

func (*BucketRequestCounter) ServeHTTP

func (m *BucketRequestCounter) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.Handler)

func (*BucketRequestCounter) Wrap

Wrap returns a handler that forwards calls to next and counts the calls forwarded

type CloseHeader

type CloseHeader struct {
	SetCloseHeader int32
}

CloseHeader is used to control when connections should signal they should be closed

func (*CloseHeader) OptionallyAddCloseHeader

func (c *CloseHeader) OptionallyAddCloseHeader(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)

OptionallyAddCloseHeader will set Connection: Close on the response if SetCloseHeader is non zero

type Constructor

type Constructor interface {
	CreateMiddleware(next ContextHandler) ContextHandler
}

Constructor defines how we creates context handling middleware

type ConstructorFunc

type ConstructorFunc func(next ContextHandler) ContextHandler

ConstructorFunc allows a func to become a Constructor

func (ConstructorFunc) CreateMiddleware

func (c ConstructorFunc) CreateMiddleware(next ContextHandler) ContextHandler

CreateMiddleware calls the underline function

type ContextHandler

type ContextHandler interface {
	ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request)
}

ContextHandler is just like http.Handler but also takes a context

func FromHTTP

func FromHTTP(f http.Handler) ContextHandler

FromHTTP creates a ContextHandler from a http.Handler by throwing away the context

type CtxWithFlag

type CtxWithFlag struct {
	CtxFlagger *log.CtxDimensions
	HeaderName string
}

CtxWithFlag adds useful request parameters to the logging context, as well as a random request_id to the request

func (*CtxWithFlag) CreateMiddleware

func (m *CtxWithFlag) CreateMiddleware(next ContextHandler) ContextHandler

CreateMiddleware creates a handler that calls next as the next in the chain

func (*CtxWithFlag) ServeHTTPC

func (m *CtxWithFlag) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)

ServeHTTPC adds useful request dims to the next context

type FastRequestLimitDuration

type FastRequestLimitDuration interface {
	Get() time.Duration
}

FastRequestLimitDuration is the interface for getting the cutoff time for bad requests.

type HTTPConstructor

type HTTPConstructor func(next http.Handler) http.Handler

HTTPConstructor is generally discouraged but allows us to turn a normal http.Handler constructor into a context constructor

func (HTTPConstructor) CreateMiddleware

func (h HTTPConstructor) CreateMiddleware(next ContextHandler) ContextHandler

CreateMiddleware creates a middleware layer for a HTTPConstructor. It is unsafe to call this ContextHandler from multiple threads. Our Handler layer will make sure this doesn't happen

type Handler

type Handler struct {
	Ending          ContextHandler
	Chain           []Constructor
	StartingContext context.Context
	Pool            sync.Pool
}

Handler turns a stack of HTTP handlers into a single handler that threads a context between each

func NewHandler

func NewHandler(StartingContext context.Context, Ending ContextHandler) *Handler

NewHandler creates a new handler with no middleware layers

func (*Handler) Add

func (h *Handler) Add(parts ...Constructor) *Handler

Add a middleware layer to this handler

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP passes the default starting context

func (*Handler) ServeHTTPC

func (h *Handler) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request)

ServeHTTPC will pass the request between each middleware layer

type HandlerFunc

type HandlerFunc func(ctx context.Context, rw http.ResponseWriter, r *http.Request)

HandlerFunc can turn a func() into a ContextHandler

func (HandlerFunc) ServeHTTPC

func (h HandlerFunc) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request)

ServeHTTPC calls the underline func

type HeaderCtxFlag

type HeaderCtxFlag struct {
	HeaderName string
	// contains filtered or unexported fields
}

HeaderCtxFlag sets a debug value in the context if HeaderName is not empty, a flag string has been set to non empty, and the header HeaderName or query string HeaderName is equal to the set flag string

func (*HeaderCtxFlag) CreateMiddleware

func (m *HeaderCtxFlag) CreateMiddleware(next ContextHandler) ContextHandler

CreateMiddleware creates a handler that calls next as the next in the chain

func (*HeaderCtxFlag) FlagStr

func (m *HeaderCtxFlag) FlagStr() string

FlagStr returns the currently set flag header

func (*HeaderCtxFlag) HasFlag

func (m *HeaderCtxFlag) HasFlag(ctx context.Context) bool

HasFlag returns true if WithFlag has been set for this context

func (*HeaderCtxFlag) ServeHTTPC

func (m *HeaderCtxFlag) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)

ServeHTTPC calls next with a context flagged if the headers match. Note it checks both headers and query parameters.

func (*HeaderCtxFlag) SetFlagStr

func (m *HeaderCtxFlag) SetFlagStr(headerVal string)

SetFlagStr enabled flag setting for HeaderName if it's equal to headerVal

func (*HeaderCtxFlag) WithFlag

func (m *HeaderCtxFlag) WithFlag(ctx context.Context) context.Context

WithFlag returns a new Context that has the flag for this context set

type HeadersInRequest

type HeadersInRequest struct {
	Headers map[string]string
}

HeadersInRequest adds headers to any context with a flag set

func (*HeadersInRequest) CreateMiddleware

func (m *HeadersInRequest) CreateMiddleware(next ContextHandler) ContextHandler

CreateMiddleware creates a handler that calls next as the next in the chain

func (*HeadersInRequest) ServeHTTPC

func (m *HeadersInRequest) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)

ServeHTTPC will add headers to rw if ctx has the flag set

type NextConstructor

type NextConstructor func(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)

NextConstructor creates a Constructor that calls the given function to forward requests

func (NextConstructor) CreateMiddleware

func (n NextConstructor) CreateMiddleware(next ContextHandler) ContextHandler

CreateMiddleware returns a middleware layer that passes next to n()

type NextHTTP

type NextHTTP func(rw http.ResponseWriter, r *http.Request, next http.Handler)

NextHTTP is like NextConstructor but when the next praameter is a http.Handler

func (NextHTTP) CreateMiddleware

func (n NextHTTP) CreateMiddleware(next ContextHandler) ContextHandler

CreateMiddleware creates a middleware layer that saves the context for the next layer

type Recorder

type Recorder struct {
	Queue chan Request
}

Recorder stores into Queue each request that comes across the recorder

func (*Recorder) AsHandler

func (t *Recorder) AsHandler() ContextHandler

AsHandler returns a Recoder that can be a destination handler

func (*Recorder) ServeHTTP

func (t *Recorder) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP stores the request into the Queue

func (*Recorder) ServeHTTPC

func (t *Recorder) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)

ServeHTTPC stores the req into Queue and calls next

type ReqLatencyCounter

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

ReqLatencyCounter hold static data for the request latency tracking.

func NewReqLatencyCounter

func NewReqLatencyCounter(fastRequestDurationLimit FastRequestLimitDuration) ReqLatencyCounter

NewReqLatencyCounter creates a new ReqLatencyCounter

func (*ReqLatencyCounter) ModStats

func (a *ReqLatencyCounter) ModStats(ctx context.Context)

ModStats modifies the metric values for the ReqLatencyCounter.

func (*ReqLatencyCounter) ModStatsTime

func (a *ReqLatencyCounter) ModStatsTime(start time.Time)

ModStatsTime modifies the metric values for the ReqLatencyCounter.

func (*ReqLatencyCounter) Stats

func (a *ReqLatencyCounter) Stats(dimensions map[string]string) []*datapoint.Datapoint

Stats gets the metrics for a ReqLatencyCounter.

type Request

type Request struct {
	Ctx context.Context
	Rw  http.ResponseWriter
	Req *http.Request
}

Request is a request put on the TestHandler queue that records eacn request sent through

type RequestCounter

type RequestCounter struct {
	TotalConnections      int64
	ActiveConnections     int64
	TotalProcessingTimeNs int64
}

RequestCounter is a negroni handler that tracks connection stats

func (*RequestCounter) Datapoints

func (m *RequestCounter) Datapoints() []*datapoint.Datapoint

Datapoints returns stats on total connections, active connections, and total processing time

func (*RequestCounter) ServeHTTP

func (m *RequestCounter) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.Handler)

func (*RequestCounter) Wrap

func (m *RequestCounter) Wrap(next http.Handler) http.Handler

Wrap returns a handler that forwards calls to next and counts the calls forwarded

type VarAdder

type VarAdder struct {
	Key   interface{}
	Value interface{}
}

VarAdder is a middleware layer that adds to the context Key/Value

func (*VarAdder) Generate

func (i *VarAdder) Generate(next ContextHandler) ContextHandler

Generate creates the next middleware layer for VarAdder

Jump to

Keyboard shortcuts

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