middleware

package
Version: v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2014 License: Apache-2.0, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Middlewares can modify or intercept requests and responses

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware interface {
	// Called before the request is going to be proxied to the endpoint selected by the load balancer.
	// If it returns an error, request will be treated as erorrneous (e.g. failover will be initated).
	// If it returns a non nil response, proxy will return the response without proxying to the endpoint.
	// If it returns nil response and nil error request will be proxied to the upstream.
	// It's ok to modify request headers and body as a side effect of the funciton call.
	ProcessRequest(r Request) (*http.Response, error)

	// If request has been completed or intercepted by middleware and response has been received
	// attempt would contain non nil response or non nil error.
	ProcessResponse(r Request, a Attempt)
}

Middlewares are allowed to observe, modify and intercept http requests and responses

type MiddlewareChain

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

Middleware chain implements middleware interface and acts as a container for multiple middlewares chained together in deterministic order.

func NewMiddlewareChain

func NewMiddlewareChain() *MiddlewareChain

func (*MiddlewareChain) Add

func (c *MiddlewareChain) Add(id string, priority int, m Middleware) error

func (*MiddlewareChain) Get

func (c *MiddlewareChain) Get(id string) Middleware

func (*MiddlewareChain) GetIter

func (c *MiddlewareChain) GetIter() *MiddlewareIter

func (*MiddlewareChain) Remove

func (c *MiddlewareChain) Remove(id string) error

func (*MiddlewareChain) Update

func (c *MiddlewareChain) Update(id string, priority int, m Middleware) error

func (*MiddlewareChain) Upsert

func (c *MiddlewareChain) Upsert(id string, priority int, m Middleware)

type MiddlewareIter

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

func (*MiddlewareIter) Next

func (m *MiddlewareIter) Next() Middleware

func (*MiddlewareIter) Prev

func (m *MiddlewareIter) Prev() Middleware

type MiddlewareWrapper

type MiddlewareWrapper struct {
	OnRequest  ProcessRequestFn
	OnResponse ProcessResponseFn
}

Wraps the functions to create a middleware compatible interface

func (*MiddlewareWrapper) ProcessRequest

func (cb *MiddlewareWrapper) ProcessRequest(r Request) (*http.Response, error)

func (*MiddlewareWrapper) ProcessResponse

func (cb *MiddlewareWrapper) ProcessResponse(r Request, a Attempt)

type ObserveRequestFn

type ObserveRequestFn func(r Request)

type ObserveResponseFn

type ObserveResponseFn func(r Request, a Attempt)

type Observer

type Observer interface {
	// Will be called before every request to the endpoint
	ObserveRequest(r Request)

	// Will be called after every request to the endpoint
	ObserveResponse(r Request, a Attempt)
}

Unlinke middlewares, observers are not able to intercept or change any requests and will be called on every request to endpoint regardless of the middlewares side effects

type ObserverChain

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

func NewObserverChain

func NewObserverChain() *ObserverChain

func (*ObserverChain) Add

func (c *ObserverChain) Add(id string, o Observer) error

func (*ObserverChain) Get

func (c *ObserverChain) Get(id string) Observer

func (*ObserverChain) ObserveRequest

func (c *ObserverChain) ObserveRequest(r Request)

func (*ObserverChain) ObserveResponse

func (c *ObserverChain) ObserveResponse(r Request, a Attempt)

func (*ObserverChain) Remove

func (c *ObserverChain) Remove(id string) error

func (*ObserverChain) Update

func (c *ObserverChain) Update(id string, o Observer) error

func (*ObserverChain) Upsert

func (c *ObserverChain) Upsert(id string, o Observer)

type ObserverWrapper

type ObserverWrapper struct {
	OnRequest  ObserveRequestFn
	OnResponse ObserveResponseFn
}

Wraps the functions to create a observer compatible interface

func (*ObserverWrapper) ObserveRequest

func (cb *ObserverWrapper) ObserveRequest(r Request)

func (*ObserverWrapper) ObserveResponse

func (cb *ObserverWrapper) ObserveResponse(r Request, a Attempt)

type ProcessRequestFn

type ProcessRequestFn func(r Request) (*http.Response, error)

type ProcessResponseFn

type ProcessResponseFn func(r Request, a Attempt)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL