middleware

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2017 License: Apache-2.0 Imports: 21 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHTTPS

func IsHTTPS(r *rest.Request) bool

IsHTTPS returns true if the request is using https protocol or false otherwise

func IsProxiedHTTPS

func IsProxiedHTTPS(r *rest.Request) bool

IsProxiedHTTPS returns true if the original request is using https protocol or false otherwise

func IsUsingSecureConnection

func IsUsingSecureConnection(r *rest.Request) bool

IsUsingSecureConnection returns true if the request is using secure connection or false otherwise

Types

type AccessLog

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

AccessLog produces the access log. It depends on TimerMiddleware and RecorderMiddleware that should be in the wrapped middlewares. It also uses request.Env[Namespace] set by the auth middlewares.

func (*AccessLog) MiddlewareFunc

func (mw *AccessLog) MiddlewareFunc(h rest.HandlerFunc) rest.HandlerFunc

MiddlewareFunc makes AccessLogApacheMiddleware implement the Middleware interface.

type AuthMiddleware

type AuthMiddleware struct {
	TokenRouteParam string
	Authenticator   auth.Authenticator
}

AuthMiddleware provides a generic authentication middleware On failure, a 401 HTTP response is returned. On success, the wrapped middleware is called.

func (*AuthMiddleware) MiddlewareFunc

func (mw *AuthMiddleware) MiddlewareFunc(handler rest.HandlerFunc) rest.HandlerFunc

MiddlewareFunc returns a go-json-rest HTTP Handler function, wrapping calls to the provided HandlerFunc

type CheckRequest

type CheckRequest struct {
	// Defines a function that, given a request, determines if the request is secure or should be redirected.
	// Criteria may include, for example, scheme, X-Forward* headers, URL paths, etc. If unset, a default
	// criteria is applied, checking the request's scheme and TLS configuration
	IsSecure func(r *rest.Request) bool
	// When developing, various options can cause unwanted effects (e.g., usually testing happens on localhost with
	// http, not https, etc.). The following flag can set to true in a development environment to disable checks
	// and redirection. Default is false (i.e., it is enabled)
	Disabled bool
}

CheckRequest defines the request validation configuration used by RequireHTTPS middleware

type ContextMiddleware

type ContextMiddleware struct{}

ContextMiddleware initializes a context and puts it in the request's env map

func (*ContextMiddleware) MiddlewareFunc

func (mw *ContextMiddleware) MiddlewareFunc(h rest.HandlerFunc) rest.HandlerFunc

MiddlewareFunc makes ContextMiddleware implement the Middleware interface.

type GzipMiddleware

type GzipMiddleware struct{}

GzipMiddleware is responsible for compressing the payload with gzip and setting the proper headers when supported by the client.

func (*GzipMiddleware) MiddlewareFunc

func (mw *GzipMiddleware) MiddlewareFunc(h rest.HandlerFunc) rest.HandlerFunc

MiddlewareFunc makes GzipMiddleware implement the Middleware interface.

type MetricsMiddleware

type MetricsMiddleware struct{}

MetricsMiddleware is an HTTP middleware that collects API usage metrics. It depends on the "ELAPSED_TIME" and "STATUS_CODE" being in r.Env (injected by rest.TimerMiddleware / rest.RecorderMiddleware), as well as the protocol.ProtocolKey and protocol.OperationKey values.

func (*MetricsMiddleware) MiddlewareFunc

func (mw *MetricsMiddleware) MiddlewareFunc(h rest.HandlerFunc) rest.HandlerFunc

MiddlewareFunc implements the Middleware interface

type NameGenerator

type NameGenerator interface {
	// Generate a sequence of n characters
	Generate(n int) string
}

NameGenerator generates unique sequence of strings from the provided dictionary

func NewNameGenerator

func NewNameGenerator(dictionary string) NameGenerator

NewNameGenerator creates a new generator of random string sequences from the requested dictionary

type RequireHTTPS

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

RequireHTTPS provide HTTP middleware to ensure requests are received over secure communication. By default, all requests using HTTP are redirected to the corresponding HTTPS URL.

func NewRequireHTTPS

func NewRequireHTTPS(checkConfig CheckRequest) *RequireHTTPS

NewRequireHTTPS creates a new middleware with the given checks configured

func (*RequireHTTPS) MiddlewareFunc

func (secure *RequireHTTPS) MiddlewareFunc(handler rest.HandlerFunc) rest.HandlerFunc

MiddlewareFunc returns a go-json-rest HTTP Handler function, wrapping calls to the provided HandlerFunc

type Trace

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

Trace provides mechanism to add headers to each response returned by the server the implementation leaves to the user to specify the header name/label and format the value as any string may it be a comma separated multi-value string.

func NewTrace

func NewTrace() *Trace

NewTrace creates and initialize a trace middleware

func (*Trace) AddHeader

func (mw *Trace) AddHeader(key, value string)

AddHeader adds the key, value pair to the header. It appends to any existing values associated with key.

func (*Trace) MiddlewareFunc

func (mw *Trace) MiddlewareFunc(handler rest.HandlerFunc) rest.HandlerFunc

MiddlewareFunc returns a go-json-rest HTTP Handler function, wrapping calls to the provided HandlerFunc

Jump to

Keyboard shortcuts

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