http

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LastHeaderValue

func LastHeaderValue(header http.Header, key string) string

LastHeaderValue gets the last value associated with the given key. It is case insensitive; textproto.CanonicalMIMEHeaderKey is used to canonicalize the provided key. If there are no values associated with the key, Get returns "".

Types

type RequestLogHandler

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

RequestLogHandler implements an http.Handler that writes request logs and calls the next handler.

func NewRequestLogHandler

func NewRequestLogHandler(h http.Handler, w io.Writer, templateStr string,
	inputGetter RequestLogTemplateInputGetter, enableProbeRequestLog bool) (*RequestLogHandler, error)

NewRequestLogHandler creates an http.Handler that logs request logs to an io.Writer.

func (*RequestLogHandler) ServeHTTP

func (h *RequestLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*RequestLogHandler) SetTemplate

func (h *RequestLogHandler) SetTemplate(templateStr string) error

SetTemplate sets the template to use for formatting request logs. Setting the template to an empty string turns of writing request logs.

type RequestLogResponse

type RequestLogResponse struct {
	Code    int
	Size    int
	Latency float64
}

RequestLogResponse provided response related information for the template execution.

type RequestLogRevision

type RequestLogRevision struct {
	Name          string
	Namespace     string
	Service       string
	Configuration string
	PodName       string
	PodIP         string
}

RequestLogRevision provides revision related static information for the template execution.

type RequestLogTemplateInput

type RequestLogTemplateInput struct {
	Request  *http.Request
	Response *RequestLogResponse
	Revision *RequestLogRevision
}

RequestLogTemplateInput is the wrapper struct that provides all necessary information for the template execution.

type RequestLogTemplateInputGetter

type RequestLogTemplateInputGetter func(req *http.Request, resp *RequestLogResponse) *RequestLogTemplateInput

RequestLogTemplateInputGetter defines a function returning the input to pass to a request log writer.

func RequestLogTemplateInputGetterFromRevision

func RequestLogTemplateInputGetterFromRevision(rev *RequestLogRevision) RequestLogTemplateInputGetter

RequestLogTemplateInputGetterFromRevision returns a func that forms a template input using a static revision information.

type ResponseRecorder

type ResponseRecorder struct {
	ResponseCode int
	ResponseSize int32
	// contains filtered or unexported fields
}

ResponseRecorder is an implementation of http.ResponseWriter and http.Flusher that captures the response code and size.

func NewResponseRecorder

func NewResponseRecorder(w http.ResponseWriter, responseCode int) *ResponseRecorder

NewResponseRecorder creates an http.ResponseWriter that captures the response code and size.

func (*ResponseRecorder) Flush

func (rr *ResponseRecorder) Flush()

Flush flushes the buffer to the client.

func (*ResponseRecorder) Header

func (rr *ResponseRecorder) Header() http.Header

Header returns the header map that will be sent by WriteHeader.

func (*ResponseRecorder) Hijack

func (rr *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack calls Hijack() on the wrapped http.ResponseWriter if it implements http.Hijacker interface, which is required for net/http/httputil/reverseproxy to handle connection upgrade/switching protocol. Otherwise returns an error.

func (*ResponseRecorder) Write

func (rr *ResponseRecorder) Write(p []byte) (int, error)

Write writes the data to the connection as part of an HTTP reply.

func (*ResponseRecorder) WriteHeader

func (rr *ResponseRecorder) WriteHeader(code int)

WriteHeader sends an HTTP response header with the provided status code.

Jump to

Keyboard shortcuts

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