Movatterモバイル変換


[0]ホーム

URL:


httprec

package
v1.92.3Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License:BSD-3-ClauseImports:6Imported by:1

Details

Repository

github.com/tailscale/tailscale

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

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.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp