oxy: github.com/vulcand/oxy/utils Index | Files

package utils

import "github.com/vulcand/oxy/utils"

Index

Package Files

auth.go dumpreq.go handler.go netutils.go source.go

Constants

const StatusClientClosedRequest = 499

StatusClientClosedRequest non-standard HTTP status code for client disconnection

const StatusClientClosedRequestText = "Client Closed Request"

StatusClientClosedRequestText non-standard HTTP status for client disconnection

func CopyHeaders Uses

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 Uses

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

CopyURL provides update safe copy by avoiding shallow copying User field

func DumpHttpRequest Uses

func DumpHttpRequest(req *http.Request) string

DumpHttpRequest dump a HTTP request to JSON

func HasHeaders Uses

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

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

func NopWriteCloser Uses

func NopWriteCloser(w io.Writer) io.WriteCloser

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

func RemoveHeaders Uses

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

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

type BasicAuth Uses

type BasicAuth struct {
    Username string
    Password string
}

BasicAuth basic auth information

func ParseAuthHeader Uses

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

ParseAuthHeader creates a new BasicAuth from header values

func (*BasicAuth) String Uses

func (ba *BasicAuth) String() string

type BufferWriter Uses

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

BufferWriter buffer writer

func NewBufferWriter Uses

func NewBufferWriter(w io.WriteCloser) *BufferWriter

NewBufferWriter creates a new BufferWriter

func (*BufferWriter) Close Uses

func (b *BufferWriter) Close() error

Close close the writer

func (*BufferWriter) CloseNotify Uses

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

CloseNotify returns a channel that receives at most a single value (true) when the client connection has gone away.

func (*BufferWriter) Header Uses

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

Header gets response header

func (*BufferWriter) Hijack Uses

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

Hijack lets the caller take over the connection.

func (*BufferWriter) Write Uses

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

func (*BufferWriter) WriteHeader Uses

func (b *BufferWriter) WriteHeader(code int)

WriteHeader writes status code

type ErrorHandler Uses

type ErrorHandler interface {
    ServeHTTP(w http.ResponseWriter, req *http.Request, err error)
}

ErrorHandler error handler

var DefaultHandler ErrorHandler = &StdHandler{}

DefaultHandler default error handler

type ErrorHandlerFunc Uses

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

ErrorHandlerFunc error handler function type

func (ErrorHandlerFunc) ServeHTTP Uses

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

ServeHTTP calls f(w, r).

type ExtractSource Uses

type ExtractSource func(req *http.Request)

ExtractSource extract source function type

type ExtractorFunc Uses

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

ExtractorFunc extractor function type

func (ExtractorFunc) Extract Uses

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

Extract extract from request

type ProxyWriter Uses

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

ProxyWriter calls recorder, used to debug logs

func NewProxyWriter Uses

func NewProxyWriter(w http.ResponseWriter) *ProxyWriter

NewProxyWriter creates a new ProxyWriter

func NewProxyWriterWithLogger Uses

func NewProxyWriterWithLogger(w http.ResponseWriter, l *log.Logger) *ProxyWriter

NewProxyWriterWithLogger creates a new ProxyWriter

func (*ProxyWriter) CloseNotify Uses

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

CloseNotify returns a channel that receives at most a single value (true) when the client connection has gone away.

func (*ProxyWriter) Flush Uses

func (p *ProxyWriter) Flush()

Flush flush the writer

func (*ProxyWriter) GetLength Uses

func (p *ProxyWriter) GetLength() int64

GetLength gets content length

func (*ProxyWriter) Header Uses

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

Header gets response header

func (*ProxyWriter) Hijack Uses

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

Hijack lets the caller take over the connection.

func (*ProxyWriter) StatusCode Uses

func (p *ProxyWriter) StatusCode() int

StatusCode gets status code

func (*ProxyWriter) Write Uses

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

func (*ProxyWriter) WriteHeader Uses

func (p *ProxyWriter) WriteHeader(code int)

WriteHeader writes status code

type SerializableHttpRequest Uses

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
}

SerializableHttpRequest serializable HTTP request

func Clone Uses

func Clone(r *http.Request) *SerializableHttpRequest

Clone clone a request

func (*SerializableHttpRequest) ToJson Uses

func (s *SerializableHttpRequest) ToJson() string

ToJson serializes to JSON

type SourceExtractor Uses

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

SourceExtractor 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 Uses

func NewExtractor(variable string) (SourceExtractor, error)

NewExtractor creates a new SourceExtractor

type StdHandler Uses

type StdHandler struct{}

StdHandler Standard error handler

func (*StdHandler) ServeHTTP Uses

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

Package utils imports 14 packages (graph) and is imported by 311 packages. Updated 2018-08-18. Refresh now. Tools for package owners.