Package-Level Type Names (total 3, in which 2 are exported)
/* sort exporteds by: | */
ResponseRecorder is an implementation of http.ResponseWriter that
records its mutations for later inspection in tests.
Body is the buffer to which the Handler's Write calls are sent.
If nil, the Writes are silently discarded.
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.
Flushed is whether the Handler called Flush.
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.
// cache of Result's return value
// snapshot of HeaderMap at first Write
wroteHeaderbool
Flush implements http.Flusher. To test whether Flush was
called, see rw.Flushed.
Header implements http.ResponseWriter. It returns the response
headers to mutate within a handler. To test the headers that were
written after a handler completes, use the Result method and see
the returned Response value's Header.
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.
Write implements http.ResponseWriter. The data in buf is written to
rw.Body, if not nil.
WriteHeader implements http.ResponseWriter.
WriteString implements io.StringWriter. The data in str is written
to rw.Body, if not nil.
writeHeader writes a header if it was not written yet and
detects Content-Type if needed.
bytes or str are the beginning of the response body.
We pass both to avoid unnecessarily generate garbage
in rw.WriteString which was created for performance reasons.
Non-nil bytes win.
*ResponseRecorder : net/http.Flusher
*ResponseRecorder : net/http.ResponseWriter
*ResponseRecorder : io.StringWriter
*ResponseRecorder : io.Writer
*ResponseRecorder : net/http.http2stringWriter
*ResponseRecorder : net/http/httputil.writeFlusher
*ResponseRecorder : golang.org/x/net/http2.stringWriter
func NewRecorder() *ResponseRecorder
A Server is an HTTP server listening on a system-chosen port on the
local loopback interface, for use in end-to-end HTTP tests.
Config may be changed after calling NewUnstartedServer and
before Start or StartTLS.
EnableHTTP2 controls whether HTTP/2 is enabled
on the server. It must be set between calling
NewUnstartedServer and calling Server.StartTLS.
Listenernet.Listener
TLS is the optional TLS configuration, populated with a new config
after TLS is started. If set on an unstarted server before StartTLS
is called, existing fields are copied into the new config.
// base URL of form http://ipaddr:port with no trailing slash
certificate is a parsed version of the TLS config certificate, if present.
client is configured for use with the server.
Its transport is automatically closed when Close is called.
closedbool
// except terminal states
// guards closed and conns
wg counts the number of outstanding HTTP requests on this server.
Close blocks until all requests are finished.
Certificate returns the certificate used by the server, or nil if
the server doesn't use TLS.
Client returns an HTTP client configured for making requests to the server.
It is configured to trust the server's TLS test certificate and will
close its idle connections on Server.Close.
Close shuts down the server and blocks until all outstanding
requests on this server have completed.
CloseClientConnections closes any open HTTP connections to the test Server.
Start starts a server from NewUnstartedServer.
StartTLS starts TLS on a server from NewUnstartedServer.
closeConn closes c.
s.mu must be held.
closeConnChan is like closeConn, but takes an optional channel to receive a value
when the goroutine closing c is done.
(*Server) goServe()(*Server) logCloseHangDebugInfo()
wrap installs the connection state-tracking hook to know which
connections are idle.
func NewServer(handler http.Handler) *Server
func NewTLSServer(handler http.Handler) *Server
func NewUnstartedServer(handler http.Handler) *Server
Package-Level Functions (total 10, in which 5 are exported)
NewRecorder returns an initialized ResponseRecorder.
NewRequest returns a new incoming server Request, suitable
for passing to an http.Handler for testing.
The target is the RFC 7230 "request-target": it may be either a
path or an absolute URL. If target is an absolute URL, the host name
from the URL is used. Otherwise, "example.com" is used.
The TLS field is set to a non-nil dummy value if target has scheme
"https".
The Request.Proto is always HTTP/1.1.
An empty method means "GET".
The provided body may be nil. If the body is of type *bytes.Reader,
*strings.Reader, or *bytes.Buffer, the Request.ContentLength is
set.
NewRequest panics on error for ease of use in testing, where a
panic is acceptable.
To generate a client HTTP request instead of a server request, see
the NewRequest function in the net/http package.
NewServer starts and returns a new Server.
The caller should call Close when finished, to shut it down.
NewTLSServer starts and returns a new Server using TLS.
The caller should call Close when finished, to shut it down.
NewUnstartedServer returns a new Server but doesn't start it.
After changing its configuration, the caller should call Start or
StartTLS.
The caller should call Close when finished, to shut it down.
parseContentLength trims whitespace from s and returns -1 if no value
is set, or the value if it's >= 0.
This a modified version of same function found in net/http/transfer.go. This
one just ignores an invalid header.
Package-Level Variables (only one, which is unexported)
When debugging a particular http server-based test,
this flag lets you run
go test -run=BrokenTest -httptest.serve=127.0.0.1:8000
to start the broken server so you can interact with it manually.
We only register this flag if it looks like the caller knows about it
and is trying to use it as we don't want to pollute flags and this
isn't really part of our API. Don't depend on this.
Package-Level Constants (only one, which is exported)
DefaultRemoteAddr is the default remote address to return in RemoteAddr if
an explicit DefaultRemoteAddr isn't set on ResponseRecorder.
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)