lib

package
v0.0.0-...-df37d59 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRemoteAddr = "1.2.3.4"

DefaultRemoteAddr is the default remote address to return in RemoteAddr if an explicit DefaultRemoteAddr isn't set on ResponseRecorder.

Variables

This section is empty.

Functions

func GenCA

func GenCA(name string) (certPEM, keyPEM []byte, err error)

func IOCopy

func IOCopy(w io.Writer, r *ResponseRecorder, reformatJSON bool)

func ParseHeadersAndPostBody

func ParseHeadersAndPostBody(headers, post string, multipartPOST bool, req *http.Request) (err error)

func ParseSetCookies

func ParseSetCookies(headers http.Header) []*http.Cookie

func PrettySize

func PrettySize(bytes int64) string

func TryLoadCert

func TryLoadCert() (tls.Certificate, int, int)

func WebConsoleHTTPHandler

func WebConsoleHTTPHandler(proxy *pp.ProxyClient) func(w http.ResponseWriter, r *http.Request)

Types

type NullReader

type NullReader struct{}

func (*NullReader) Close

func (r *NullReader) Close() error

func (*NullReader) Read

func (r *NullReader) Read(p []byte) (int, error)

type ResponseRecorder

type ResponseRecorder struct {
	Code      int
	HeaderMap http.Header
	Flushed   bool
	Body      io.ReadCloser
	// contains filtered or unexported fields
}

ResponseRecorder is an implementation of http.ResponseWriter that records its mutations for later inspection in tests.

func NewRecorder

func NewRecorder(callback func(bytes int64)) *ResponseRecorder

NewRecorder returns an initialized ResponseRecorder.

func (*ResponseRecorder) Header

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

Header returns the response headers.

func (*ResponseRecorder) IsRedir

func (rw *ResponseRecorder) IsRedir() bool

func (*ResponseRecorder) Result

func (rw *ResponseRecorder) Result() *http.Response

Result returns the response generated by the handler.

The returned Response will have at least its StatusCode, Header, Body, and optionally Trailer populated. More fields may be populated in the future, so callers should not DeepEqual the result in tests.

The Response.Header is a snapshot of the headers at the time of the first write call, or at the time of this call, if the handler never did a write.

The Response.Body is guaranteed to be non-nil and Body.Read call is guaranteed to not return any error other than io.EOF.

Result must only be called after the handler has finished running.

Coyove: note this method will not dump body

func (*ResponseRecorder) SetBody

func (rw *ResponseRecorder) SetBody(r io.ReadCloser)

func (*ResponseRecorder) Write

func (rw *ResponseRecorder) Write(buf []byte) (int, error)

func (*ResponseRecorder) WriteHeader

func (rw *ResponseRecorder) WriteHeader(code int)

WriteHeader sets rw.Code. After it is called, changing rw.Header will not affect rw.HeaderMap.

Jump to

Keyboard shortcuts

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