response_writer

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package response_writer provides legacy JSON response helpers. EXPERIMENTAL: This package is not yet API-stable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteErr

func WriteErr(w http.ResponseWriter, code int, msg string)

WriteErr writes a Problem Details error response. Deprecated: use httpx.WriteProblem or httpx.WriteError instead.

func WriteJSON

func WriteJSON(w http.ResponseWriter, code int, v any)

WriteJSON writes a JSON response. Deprecated: use httpx.WriteJSON instead.

Types

type Capture

type Capture struct {
	// contains filtered or unexported fields
}

Capture buffers response headers and body for later replay.

func NewCapture

func NewCapture() *Capture

NewCapture creates a new buffered response writer.

func (*Capture) Body

func (c *Capture) Body() []byte

Body returns a copy of the buffered body.

func (*Capture) BytesWritten

func (c *Capture) BytesWritten() int

BytesWritten returns the number of buffered bytes.

func (*Capture) Header

func (c *Capture) Header() http.Header

Header returns the buffered header map.

func (*Capture) Status

func (c *Capture) Status() int

Status returns the captured status code.

func (*Capture) Write

func (c *Capture) Write(b []byte) (int, error)

Write buffers the response body.

func (*Capture) WriteHeader

func (c *Capture) WriteHeader(code int)

WriteHeader records the status code without writing.

func (*Capture) WriteTo

func (c *Capture) WriteTo(w http.ResponseWriter)

WriteTo writes the buffered response to the provided ResponseWriter.

type Writer

type Writer struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Writer wraps an http.ResponseWriter and tracks status/bytes. It forwards optional interfaces (Flusher, Hijacker, Pusher, ReaderFrom).

func Wrap

func Wrap(w http.ResponseWriter) *Writer

Wrap returns a response writer wrapper that tracks status and bytes.

func (*Writer) BytesWritten

func (w *Writer) BytesWritten() int

BytesWritten returns the number of bytes written.

func (*Writer) Flush

func (w *Writer) Flush()

Flush forwards the flush if supported.

func (*Writer) Hijack

func (w *Writer) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack forwards hijacking if supported.

func (*Writer) Push

func (w *Writer) Push(target string, opts *http.PushOptions) error

Push forwards server push if supported.

func (*Writer) ReadFrom

func (w *Writer) ReadFrom(r io.Reader) (int64, error)

ReadFrom forwards streaming reads if supported.

func (*Writer) Status

func (w *Writer) Status() int

Status returns the last written status code.

func (*Writer) Unwrap

func (w *Writer) Unwrap() http.ResponseWriter

Unwrap returns the underlying http.ResponseWriter.

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

Write writes the response body and tracks byte count.

func (*Writer) WriteHeader

func (w *Writer) WriteHeader(code int)

WriteHeader captures the status code and forwards to the underlying writer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL