httptest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	http.Header
}

func (*Header) View

func (h *Header) View() http.Header

type ResponseRecorder

type ResponseRecorder struct {
	// Code is the HTTP response code set at initialization.
	Code int

	// HeaderMap contains the headers explicitly set by the Handler.
	// It is an internal detail.
	HeaderMap pkgHTTP.Header

	// body is the buffer to which the Handler's Write calls are sent.
	// If nil, the Writes are silently discarded.
	Body *bytes.Buffer
	// contains filtered or unexported fields
}

ResponseRecorder is an implementation of pkgHTTP.Response that records its mutations for later inspection in tests.

func NewRecorder

func NewRecorder() *ResponseRecorder

NewRecorder returns an initialized ResponseRecorder.

func (*ResponseRecorder) Header

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

Header implements pkgHTTP.Response. It returns the response headers to mutate within a handler.

func (*ResponseRecorder) ID

func (rw *ResponseRecorder) ID() uint32

ID is APISIX rpc's id.

func (*ResponseRecorder) StatusCode

func (rw *ResponseRecorder) StatusCode() int

StatusCode returns the response code.

Note that if a Handler never calls WriteHeader, this will be initial status code, rather than the implicit http.StatusOK.

func (*ResponseRecorder) Write

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

Write implements pkgHTTP.Response. The data in buf is written to rw.Body, if not nil.

func (*ResponseRecorder) WriteHeader

func (rw *ResponseRecorder) WriteHeader(code int)

WriteHeader implements pkgHTTP.Response. The statusCode is only allowed to be written once.

Jump to

Keyboard shortcuts

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