httprecorder

package module
v0.0.0-...-9f28ff7 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: MIT Imports: 16 Imported by: 0

README

HTTP Recorder

Records HTTP sessions via HTTP middleware, can view via provided handler.

image

Usage

Have a look at the simple-recorder example or do something like:

// Create an in memory recorder of max 100 requests
recorder := httprecorder.NewMemoryRecorder(100)

// host the UI outside of the middleware
go http.ListenAndServe("localhost:9001", httprecorder.UIHandler(recorder))

// Wrap some handlers with the provided middleware
mux := http.NewServeMux()
mux.HandleFunc("/", ...)
handler := httprecorder.Middleware(recorder)(mux)
http.ListenAndServe(addr, handler)

Development

The HTML template is embedded in to the source using esc

# install esc if you haven't already got it
go get -u github.com/mjibson/esc

# create static_generated.go
esc -o embedded/static_generated.go -pkg embedded assets

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(recorder Recorder) func(http.Handler) http.Handler

func UIHandler

func UIHandler(recorder Recorder) http.Handler

Types

type Interaction

type Interaction struct {
	RequestReceived  time.Time
	ResponseReceived time.Time
	Request          Request
	Response         Response
}

type MemoryRecorder

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

func NewMemoryRecorder

func NewMemoryRecorder(limit int) *MemoryRecorder

func (*MemoryRecorder) Clear

func (m *MemoryRecorder) Clear()

func (*MemoryRecorder) GetInteraction

func (m *MemoryRecorder) GetInteraction(index int) Interaction

func (*MemoryRecorder) GetInteractions

func (m *MemoryRecorder) GetInteractions(start int, length int) []Interaction

func (*MemoryRecorder) Length

func (m *MemoryRecorder) Length() int

func (*MemoryRecorder) Record

func (m *MemoryRecorder) Record(req *http.Request, requestBody []byte, resp *http.Response, requestReceived time.Time, responseReceived time.Time) error

type Recorder

type Recorder interface {
	Record(req *http.Request, requestBody []byte, resp *http.Response, requestReceived time.Time, responseReceived time.Time) error
	Length() int
	GetInteractions(start int, length int) []Interaction
	GetInteraction(index int) Interaction
	Clear()
}

type Request

type Request struct {
	Method  string
	URL     *url.URL
	Headers http.Header
	Body    []byte
}

type Response

type Response struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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