utils

package
v0.0.0-...-d11463e Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyHeaders

func CopyHeaders(dst http.Header, src http.Header)

CopyHeaders copies http headers from source to destination, it does not overide, but adds multiple headers

func CopyURL

func CopyURL(i *url.URL) *url.URL

CopyURL provides update safe copy by avoiding shallow copying User field

func DumpHttpRequest

func DumpHttpRequest(req *http.Request) string

func HasHeaders

func HasHeaders(names []string, headers http.Header) bool

HasHeaders determines whether any of the header names is present in the http headers

func NopWriteCloser

func NopWriteCloser(w io.Writer) io.WriteCloser

NopCloser returns a WriteCloser with a no-op Close method wrapping the provided Writer w.

func RemoveHeaders

func RemoveHeaders(headers http.Header, names ...string)

RemoveHeaders removes the header with the given names from the headers map

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

func ParseAuthHeader

func ParseAuthHeader(header string) (*BasicAuth, error)

func (*BasicAuth) String

func (ba *BasicAuth) String() string

type BufferWriter

type BufferWriter struct {
	H    http.Header
	Code int
	W    io.WriteCloser
}

func NewBufferWriter

func NewBufferWriter(w io.WriteCloser) *BufferWriter

func (*BufferWriter) Close

func (b *BufferWriter) Close() error

func (*BufferWriter) CloseNotify

func (b *BufferWriter) CloseNotify() <-chan bool

func (*BufferWriter) Header

func (b *BufferWriter) Header() http.Header

func (*BufferWriter) Hijack

func (b *BufferWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*BufferWriter) Write

func (b *BufferWriter) Write(buf []byte) (int, error)

func (*BufferWriter) WriteHeader

func (b *BufferWriter) WriteHeader(code int)

WriteHeader sets rw.Code.

type ErrorHandler

type ErrorHandler interface {
	ServeHTTP(w http.ResponseWriter, req *http.Request, err error)
}
var DefaultHandler ErrorHandler = &StdHandler{}

type ErrorHandlerFunc

type ErrorHandlerFunc func(http.ResponseWriter, *http.Request, error)

func (ErrorHandlerFunc) ServeHTTP

func (f ErrorHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, err error)

ServeHTTP calls f(w, r).

type ExtractSource

type ExtractSource func(req *http.Request)

type ExtractorFunc

type ExtractorFunc func(req *http.Request) (token string, amount int64, err error)

func (ExtractorFunc) Extract

func (f ExtractorFunc) Extract(req *http.Request) (string, int64, error)

type ProxyWriter

type ProxyWriter struct {
	W      http.ResponseWriter
	Code   int
	Length int64
}

ProxyWriter helps to capture response headers and status code from the ServeHTTP. It can be safely passed to ServeHTTP handler, wrapping the real response writer.

func (*ProxyWriter) CloseNotify

func (p *ProxyWriter) CloseNotify() <-chan bool

func (*ProxyWriter) Flush

func (p *ProxyWriter) Flush()

func (*ProxyWriter) Header

func (p *ProxyWriter) Header() http.Header

func (*ProxyWriter) Hijack

func (p *ProxyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*ProxyWriter) StatusCode

func (p *ProxyWriter) StatusCode() int

func (*ProxyWriter) Write

func (p *ProxyWriter) Write(buf []byte) (int, error)

func (*ProxyWriter) WriteHeader

func (p *ProxyWriter) WriteHeader(code int)

type SerializableHttpRequest

type SerializableHttpRequest struct {
	Method           string
	URL              *url.URL
	Proto            string // "HTTP/1.0"
	ProtoMajor       int    // 1
	ProtoMinor       int    // 0
	Header           http.Header
	ContentLength    int64
	TransferEncoding []string
	Host             string
	Form             url.Values
	PostForm         url.Values
	MultipartForm    *multipart.Form
	Trailer          http.Header
	RemoteAddr       string
	RequestURI       string
	TLS              *tls.ConnectionState
}

func (*SerializableHttpRequest) ToJson

func (s *SerializableHttpRequest) ToJson() string

type SourceExtractor

type SourceExtractor interface {
	Extract(req *http.Request) (token string, amount int64, err error)
}

ExtractSource extracts the source from the request, e.g. that may be client ip, or particular header that identifies the source. amount stands for amount of connections the source consumes, usually 1 for connection limiters error should be returned when source can not be identified

func NewExtractor

func NewExtractor(variable string) (SourceExtractor, error)

type StdHandler

type StdHandler struct {
}

func (*StdHandler) ServeHTTP

func (e *StdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request, err error)

Jump to

Keyboard shortcuts

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