utils

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: Apache-2.0 Imports: 14 Imported by: 483

Documentation

Index

Constants

View Source
const StatusClientClosedRequest = 499

StatusClientClosedRequest non-standard HTTP status code for client disconnection.

View Source
const StatusClientClosedRequestText = "Client Closed Request"

StatusClientClosedRequestText non-standard HTTP status for client disconnection.

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 override, 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 added in v1.4.0

func DumpHTTPRequest(req *http.Request) string

DumpHTTPRequest dump a HTTP request to JSON.

func DumpHttpRequest

func DumpHttpRequest(req *http.Request) string

DumpHttpRequest dump a HTTP request to JSON. Deprecated: use DumpHTTPRequest instead.

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

NopWriteCloser 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
}

BasicAuth basic auth information.

func ParseAuthHeader

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

ParseAuthHeader creates a new BasicAuth from header values.

func (*BasicAuth) String

func (ba *BasicAuth) String() string

type BufferWriter

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

BufferWriter buffer writer.

func NewBufferWriter

func NewBufferWriter(w io.WriteCloser) *BufferWriter

NewBufferWriter creates a new BufferWriter.

func (*BufferWriter) Close

func (b *BufferWriter) Close() error

Close close the writer.

func (*BufferWriter) CloseNotify

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

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

Header gets response header.

func (*BufferWriter) Hijack

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

Hijack lets the caller take over the connection.

func (*BufferWriter) Write

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

func (*BufferWriter) WriteHeader

func (b *BufferWriter) WriteHeader(code int)

WriteHeader writes status code.

type ErrorHandler

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

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

ErrorHandlerFunc error handler function type.

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)

ExtractSource extract source function type.

type ExtractorFunc

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

ExtractorFunc extractor function type.

func (ExtractorFunc) Extract

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

Extract extract from request.

type ProxyWriter

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

ProxyWriter calls recorder, used to debug logs.

func NewProxyWriter

func NewProxyWriter(w http.ResponseWriter) *ProxyWriter

NewProxyWriter creates a new ProxyWriter.

func NewProxyWriterWithLogger

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

NewProxyWriterWithLogger creates a new ProxyWriter.

func (*ProxyWriter) CloseNotify

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

func (p *ProxyWriter) Flush()

Flush flush the writer.

func (*ProxyWriter) GetLength

func (p *ProxyWriter) GetLength() int64

GetLength gets content length.

func (*ProxyWriter) Header

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

Header gets response header.

func (*ProxyWriter) Hijack

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

Hijack lets the caller take over the connection.

func (*ProxyWriter) StatusCode

func (p *ProxyWriter) StatusCode() int

StatusCode gets status code.

func (*ProxyWriter) Write

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

func (*ProxyWriter) WriteHeader

func (p *ProxyWriter) WriteHeader(code int)

WriteHeader writes status code.

type SerializableHTTPRequest added in v1.4.0

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

Clone clone a request.

func (*SerializableHTTPRequest) ToJSON added in v1.4.0

func (s *SerializableHTTPRequest) ToJSON() string

ToJSON serializes to JSON.

func (*SerializableHTTPRequest) ToJson added in v1.4.0

func (s *SerializableHTTPRequest) ToJson() string

ToJson serializes to JSON. Deprecated: use ToJSON instead.

type SerializableHttpRequest

type SerializableHttpRequest = SerializableHTTPRequest

SerializableHttpRequest alias on SerializableHTTPRequest. Deprecated: use SerializableHTTPRequest instead.

type SourceExtractor

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

func NewExtractor(variable string) (SourceExtractor, error)

NewExtractor creates a new SourceExtractor.

type StdHandler

type StdHandler struct{}

StdHandler Standard error handler.

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