messageview

package
v0.0.0-...-a83446c Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package messageview provides no-op snapshots for HTTP requests and responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageView

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

MessageView is a static view of an HTTP request or response.

func New

func New() *MessageView

New returns a new MessageView.

func (*MessageView) BodyReader

func (mv *MessageView) BodyReader(opts ...Option) (io.ReadCloser, error)

BodyReader returns an io.ReadCloser that reads the HTTP request or response body. If mv.skipBody was set the reader will immediately return io.EOF.

If the Decode option is passed the body will be unchunked if Transfer-Encoding is set to "chunked", and will decode the following Content-Encodings: gzip, deflate.

func (*MessageView) HeaderReader

func (mv *MessageView) HeaderReader() io.Reader

HeaderReader returns an io.Reader that reads the HTTP Status-Line or HTTP Request-Line and headers.

func (*MessageView) Reader

func (mv *MessageView) Reader(opts ...Option) (io.ReadCloser, error)

Reader returns the an io.ReadCloser that reads the full HTTP message.

func (*MessageView) SkipBody

func (mv *MessageView) SkipBody(skipBody bool)

SkipBody will skip reading the body when the view is loaded with a request or response.

func (*MessageView) SkipBodyUnlessContentType

func (mv *MessageView) SkipBodyUnlessContentType(cts ...string)

SkipBodyUnlessContentType will skip reading the body unless the Content-Type matches one in cts.

func (*MessageView) SnapshotRequest

func (mv *MessageView) SnapshotRequest(req *http.Request) error

SnapshotRequest reads the request into the MessageView. If mv.skipBody is false it will also read the body into memory and replace the existing body with the in-memory copy. This method is semantically a no-op.

func (*MessageView) SnapshotResponse

func (mv *MessageView) SnapshotResponse(res *http.Response) error

SnapshotResponse reads the response into the MessageView. If mv.headersOnly is false it will also read the body into memory and replace the existing body with the in-memory copy. This method is semantically a no-op.

func (*MessageView) TrailerReader

func (mv *MessageView) TrailerReader() io.Reader

TrailerReader returns an io.Reader that reads the HTTP request or response trailers, if present.

type Option

type Option func(*config)

Option is a configuration option for a MessageView.

func Decode

func Decode() Option

Decode sets an option to decode the message body for logging purposes.

Jump to

Keyboard shortcuts

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