httprec
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package httprec is a copy of the Go standard library's httptest.ResponseRecordertype, which we want to use in non-test code without pulling in the rest ofthe httptest package and its test certs, etc.
Index¶
- type ResponseRecorder
- func (rw *ResponseRecorder) Flush()
- func (rw *ResponseRecorder) Header() http.Header
- func (rw *ResponseRecorder) Result() *http.Response
- func (rw *ResponseRecorder) Write(buf []byte) (int, error)
- func (rw *ResponseRecorder) WriteHeader(code int)
- func (rw *ResponseRecorder) WriteString(str string) (int, error)
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeResponseRecorder¶
type ResponseRecorder struct {// Code is the HTTP response code set by WriteHeader.//// Note that if a Handler never calls WriteHeader or Write,// this might end up being 0, rather than the implicit// http.StatusOK. To get the implicit value, use the Result// method.Codeint// HeaderMap contains the headers explicitly set by the Handler.// It is an internal detail.//// Deprecated: HeaderMap exists for historical compatibility// and should not be used. To access the headers returned by a handler,// use the Response.Header map as returned by the Result method.HeaderMaphttp.Header// Body is the buffer to which the Handler's Write calls are sent.// If nil, the Writes are silently discarded.Body *bytes.Buffer// Flushed is whether the Handler called Flush.Flushedbool// contains filtered or unexported fields}ResponseRecorder is an implementation ofhttp.ResponseWriter thatrecords its mutations for later inspection in tests.
funcNewRecorder¶
func NewRecorder() *ResponseRecorder
NewRecorder returns an initializedResponseRecorder.
func (*ResponseRecorder)Flush¶
func (rw *ResponseRecorder) Flush()
Flush implementshttp.Flusher. To test whether Flush wascalled, see rw.Flushed.
func (*ResponseRecorder)Header¶
func (rw *ResponseRecorder) Header()http.Header
Header implementshttp.ResponseWriter. It returns the responseheaders to mutate within a handler. To test the headers that werewritten after a handler completes, use theResponseRecorder.Result method and seethe returned Response value's Header.
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 shouldnot DeepEqual the result in tests.
The Response.Header is a snapshot of the headers at the time of thefirst write call, or at the time of this call, if the handler neverdid a write.
The Response.Body is guaranteed to be non-nil and Body.Read call isguaranteed to not return any error other thanio.EOF.
Result must only be called after the handler has finished running.
func (*ResponseRecorder)Write¶
func (rw *ResponseRecorder) Write(buf []byte) (int,error)
Write implements http.ResponseWriter. The data in buf is written torw.Body, if not nil.
func (*ResponseRecorder)WriteHeader¶
func (rw *ResponseRecorder) WriteHeader(codeint)
WriteHeader implementshttp.ResponseWriter.
func (*ResponseRecorder)WriteString¶
func (rw *ResponseRecorder) WriteString(strstring) (int,error)
WriteString implementsio.StringWriter. The data in str is writtento rw.Body, if not nil.