Documentation
¶
Overview ¶
Package httpx holds the JSON response writers shared by the HTTP layers, so every one of them answers with the same envelope.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Flush ¶ added in v0.19.0
func Flush(w http.ResponseWriter)
Flush flushes w when it, or a writer it wraps, supports it.
func ReadFrom ¶ added in v0.19.0
ReadFrom copies r to w, through w's own ReadFrom when it has one (the net/http response does, and uses sendfile for a file) and through a pooled buffer otherwise. Response-writer wrappers call it from their ReadFrom after they have done their header bookkeeping.
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, code, message string)
WriteError writes the {error, code} envelope with the given status.
Types ¶
type StatusWriter ¶ added in v0.19.0
type StatusWriter struct {
http.ResponseWriter
// contains filtered or unexported fields
}
StatusWriter is the response-writer wrapper the middleware chain shares: it records the status code the handler chose and is otherwise transparent.
Every wrapper in the chain that hides a method of the writer underneath costs something real. ReadFrom is the one that matters: net/http's response implements io.ReaderFrom and serves an *os.File with sendfile(2), but only when the writer handed to iocopy.Copy still exposes it. StatusWriter forwards ReadFrom, Flush and (through Unwrap, for http.ResponseController) Hijack, SetWriteDeadline and EnableFullDuplex.
func WrapStatus ¶ added in v0.19.0
func WrapStatus(w http.ResponseWriter) *StatusWriter
WrapStatus returns w as a StatusWriter. A writer that already is one is returned as is, so the layers that all want the status code (metrics, tracing, access log, audit) share a single wrapper per request.
func (*StatusWriter) Flush ¶ added in v0.19.0
func (w *StatusWriter) Flush()
Flush forwards to the underlying writer when it can flush.
func (*StatusWriter) ReadFrom ¶ added in v0.19.0
func (w *StatusWriter) ReadFrom(r io.Reader) (int64, error)
ReadFrom forwards to the underlying writer's ReadFrom, which is what lets a file be sent with sendfile(2). A writer underneath without ReadFrom gets a pooled copy through Write.
func (*StatusWriter) SetStatus ¶ added in v0.19.0
func (w *StatusWriter) SetStatus(code int)
SetStatus overrides the recorded status without touching the response, for a layer that knows what a later layer will answer (a panic becomes a 500).
func (*StatusWriter) Status ¶ added in v0.19.0
func (w *StatusWriter) Status() int
Status is the status code written so far, 200 while none was.
func (*StatusWriter) Unwrap ¶ added in v0.19.0
func (w *StatusWriter) Unwrap() http.ResponseWriter
Unwrap lets http.ResponseController reach the underlying writer.
func (*StatusWriter) WriteHeader ¶ added in v0.19.0
func (w *StatusWriter) WriteHeader(code int)
WriteHeader records code and forwards it.