Documentation ¶
Index ¶
- type Header
- type ResponseRecorder
- func (rw *ResponseRecorder) Header() pkgHTTP.Header
- func (rw *ResponseRecorder) ID() uint32
- func (rw *ResponseRecorder) ReadBody() ([]byte, error)
- func (rw *ResponseRecorder) StatusCode() int
- func (rw *ResponseRecorder) Var(key string) ([]byte, error)
- func (rw *ResponseRecorder) Write(buf []byte) (int, error)
- func (rw *ResponseRecorder) WriteHeader(code int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 // OriginBody is the response body received by APISIX from upstream. OriginBody []byte Vars map[string][]byte // 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) ReadBody ¶ added in v0.5.0
func (rw *ResponseRecorder) ReadBody() ([]byte, error)
ReadBody implements pkgHTTP.Response.
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) Var ¶ added in v0.5.0
func (rw *ResponseRecorder) Var(key string) ([]byte, error)
Var implements pkgHTTP.Response.
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.