httpreplay

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 12 Imported by: 0

README

Build Status MIT License GoDoc

go-http-replay

Record and replay HTTP response for testing

Synopsis

Replay HTTP response or fetch from the remote:

import (
	"net/http"
	"testing"

	httpreplay "github.com/aereal/go-http-replay"
)

func Test_http_lib(t *testing.T) {
	httpClient := &http.Client{
		Transport: httpreplay.NewReplayOrFetchTransport("./testdata", http.DefaultClient),
	}
	// httpClient will behave like the client that created from NewReplayTransport but DO actual request if local cache is missing.
}

Only replay HTTP response from cache:

import (
	"net/http"
	"testing"

	httpreplay "github.com/aereal/go-http-replay"
)

func Test_http_lib(t *testing.T) {
	httpClient := &http.Client{
		Transport: httpreplay.NewReplayTransport("./testdata"),
	}
	// httpClient will not do actual request to remote sites but returns the response from local cache files.
}

See also

Author

  • aereal

Documentation

Overview

Package httpreplay is for stubbing HTTP requests/responses

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewReplayOrFetchTransport

func NewReplayOrFetchTransport(dataDir string, httpClient *http.Client) http.RoundTripper

NewReplayOrFetchTransport returns new http.RoundTripper that replays HTTP response local cache. If the cache is not available, do actual request and record the response to local cache.

func NewReplayTransport

func NewReplayTransport(dataDir string) http.RoundTripper

NewReplayTransport returns new http.RoundTripper that only replays HTTP response from local cache, do not request actually.

Types

This section is empty.

Jump to

Keyboard shortcuts

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