capture

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxBytes = 256 * 1024 * 1024

DefaultMaxBytes is the per-writer cap applied by NewCaptureResponseWriterWithLimit when callers want defense-in-depth against pathological upstream responses blowing the heap during ALB fanout. 256 MiB is generous for legitimate time-series payloads and stops one bad backend from OOMing the proxy.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaptureResponseWriter

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

CaptureResponseWriter captures the response body to a byte slice

func NewCaptureResponseWriter

func NewCaptureResponseWriter() *CaptureResponseWriter

NewCaptureResponseWriter returns a new CaptureResponseWriter

func NewCaptureResponseWriterWithLimit added in v2.0.2

func NewCaptureResponseWriterWithLimit(maxBytes int) *CaptureResponseWriter

NewCaptureResponseWriterWithLimit returns a CaptureResponseWriter that drops bytes past maxBytes and flips Truncated() to true. A non-positive maxBytes means unlimited.

func (*CaptureResponseWriter) Body

func (sw *CaptureResponseWriter) Body() []byte

Body returns the captured response body

func (*CaptureResponseWriter) Header

func (sw *CaptureResponseWriter) Header() http.Header

Header returns the response header map

func (*CaptureResponseWriter) StatusCode

func (sw *CaptureResponseWriter) StatusCode() int

StatusCode returns the captured status code

func (*CaptureResponseWriter) Truncated added in v2.0.2

func (sw *CaptureResponseWriter) Truncated() bool

Truncated reports whether Write dropped bytes due to hitting maxBytes.

func (*CaptureResponseWriter) Write

func (sw *CaptureResponseWriter) Write(b []byte) (int, error)

Write appends data to the response body. Returns len(b) even after the cap is reached so the upstream producer doesn't error or block; Truncated() surfaces the drop to the merge layer.

func (*CaptureResponseWriter) WriteHeader

func (sw *CaptureResponseWriter) WriteHeader(code int)

WriteHeader sets the status code and, when Content-Length is set and the body has not yet been grown, presizes body to skip bytes.Buffer's doubling-copies on large upstream responses. Bounded by maxBytes so a misreported huge CL cannot blow the cap.

Jump to

Keyboard shortcuts

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