replay

package module
v0.0.0-...-d04bc20 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: MIT Imports: 22 Imported by: 0

README

replay

Intercept network traffic and write tests against 3rd party APIs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneRequestWithBody

func CloneRequestWithBody(r *http.Request) *http.Request

func CloneResponseWithBody

func CloneResponseWithBody(r *http.Response) *http.Response

func HashRequest

func HashRequest(r *http.Request, filters ...RequestFilter) (hashKey string, err error)

func NewRequestRecorderMiddleware

func NewRequestRecorderMiddleware(params RequestRecorderMiddlewareParams) (func(next http.Handler) http.Handler, error)

func NewSingleResponseClient

func NewSingleResponseClient(entry Entry) *http.Client

func RequestToBuff

func RequestToBuff(r *http.Request, filters ...RequestFilter) *bytes.Buffer

func WithProxyTransport

func WithProxyTransport(client *http.Client, proxyURL *url.URL) *http.Client

Types

type ContentType

type ContentType struct {
	Size     int    `json:"size"`
	MimeType string `json:"mimeType"`
	Encoding string `json:"encoding"`
	Text     string `json:"text"`
}

type Creator

type Creator struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type Entry

type Entry struct {
	Time              float64   `json:"time"`
	IsHTTPS           bool      `json:"_isHTTPS"`
	WebSocketMessages any       `json:"_webSocketMessages"`
	RemoteDeviceIP    string    `json:"_remoteDeviceIP"`
	Timings           Timing    `json:"timings"`
	ServerAddress     string    `json:"_serverAddress"`
	IsIntercepted     bool      `json:"_isIntercepted"`
	Id                string    `json:"_id"`
	ServerIPAddress   string    `json:"serverIPAddress"`
	Name              string    `json:"_name"`
	ClientAddress     string    `json:"_clientAddress"`
	ClientBundlePath  any       `json:"_clientBundlePath"`
	Request           Request   `json:"request"`
	ServerPort        int       `json:"_serverPort"`
	ClientName        any       `json:"_clientName"`
	ClientPort        int       `json:"_clientPort"`
	Response          Response  `json:"response"`
	Comment           string    `json:"comment"`
	StartedDateTime   time.Time `json:"startedDateTime"`
}

type HarFile

type HarFile struct {
	Log Log `json:"log"`
}

func LoadHarFile

func LoadHarFile(harFilePath string) (har *HarFile, err error)
type Header struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Headers

type Headers []Header

func (Headers) ToHTTPHeader

func (h Headers) ToHTTPHeader() (ht http.Header)

type Log

type Log struct {
	Version string  `json:"version"`
	Creator Creator `json:"creator"`
	Entries []Entry `json:"entries"`
}

type PostData

type PostData struct {
	Params   []any  `json:"params"`
	Text     string `json:"text"`
	MimeType string `json:"mimeType"`
}

type QueryParam

type QueryParam struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type QueryParams

type QueryParams []QueryParam

func (QueryParams) ToURLValues

func (q QueryParams) ToURLValues() (v url.Values)

type ReplayOption

type ReplayOption func(transport *ReplayTransport) error

func WithDelHeaderFilter

func WithDelHeaderFilter(key string) ReplayOption

func WithHarDir

func WithHarDir(dirname string) ReplayOption

func WithHarFile

func WithHarFile(filename string) ReplayOption

func WithRequestFilter

func WithRequestFilter(filter RequestFilter) ReplayOption

func WithRequestRecorder

func WithRequestRecorder(rec *RequestRecorder) ReplayOption

func WithRoundTripDebugger

func WithRoundTripDebugger() ReplayOption

type ReplayTransport

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

func NewReplayTransport

func NewReplayTransport(opts ...ReplayOption) (rt *ReplayTransport, err error)

func (*ReplayTransport) NewClient

func (r *ReplayTransport) NewClient() *http.Client

func (*ReplayTransport) RoundTrip

func (r *ReplayTransport) RoundTrip(request *http.Request) (response *http.Response, err error)

type Request

type Request struct {
	Method      string        `json:"method"`
	BodySize    int           `json:"bodySize"`
	HeadersSize int           `json:"headersSize"`
	PostData    PostData      `json:"postData"`
	Cookies     []interface{} `json:"cookies"`
	Headers     Headers       `json:"headers"`
	QueryString QueryParams   `json:"queryString"`
	HttpVersion string        `json:"httpVersion"`
	Url         string        `json:"url"`
}

func (Request) Factory

func (r Request) Factory() *http.Request

type RequestFilter

type RequestFilter func(r *http.Request)

type RequestRecord

type RequestRecord struct {
	Key  string
	Buff *bytes.Buffer
}

type RequestRecorder

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

func NewRequestRecorder

func NewRequestRecorder() *RequestRecorder

type RequestRecorderMiddlewareParams

type RequestRecorderMiddlewareParams struct {
	Dir            string
	RequestFilters []RequestFilter
	Logger         zap.Logger
	Enabled        bool
	URLMapper      func(r *http.Request) url.URL
}

type Response

type Response struct {
	Status      int         `json:"status"`
	Content     ContentType `json:"content"`
	BodySize    int         `json:"bodySize"`
	HeadersSize int         `json:"headersSize"`
	Cookies     []any       `json:"cookies"`
	StatusText  string      `json:"statusText"`
	Headers     Headers     `json:"headers"`
	HttpVersion string      `json:"httpVersion"`
	RedirectURL string      `json:"redirectURL"`
}

func (Response) Factory

func (r Response) Factory() *http.Response

type ResponseFactory

type ResponseFactory func() *http.Response

type ResponseFilter

type ResponseFilter func(w *http.Response)

type SingleResponseTransport

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

func (*SingleResponseTransport) RoundTrip

func (r *SingleResponseTransport) RoundTrip(_ *http.Request) (response *http.Response, err error)

type Timing

type Timing struct {
	Connect int `json:"connect"`
	Send    int `json:"send"`
	Dns     int `json:"dns"`
	Ssl     int `json:"ssl"`
	Wait    int `json:"wait"`
	Blocked int `json:"blocked"`
	Receive int `json:"receive"`
}

Jump to

Keyboard shortcuts

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