httpx

package
v0.58.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MockConnectionError = MockResponse{0, ""}

MockConnectionError mocks a connection error

Functions

func Do

func Do(client *http.Client, request *http.Request) (*http.Response, error)

Do makes the given HTTP request using the current requestor

func SetDebug added in v0.52.0

func SetDebug(enabled bool)

func SetRequestor

func SetRequestor(requestor Requestor)

SetRequestor sets the requestor used by Request

Types

type MockRequestor added in v0.52.0

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

func NewMockRequestor

func NewMockRequestor(mocks map[string][]MockResponse) *MockRequestor

func (*MockRequestor) Clone added in v0.54.0

func (r *MockRequestor) Clone() *MockRequestor

Clone returns a clone of this requestor

func (*MockRequestor) Do added in v0.52.0

func (r *MockRequestor) Do(client *http.Client, request *http.Request) (*http.Response, error)

func (*MockRequestor) HasUnused added in v0.52.0

func (r *MockRequestor) HasUnused() bool

HasUnused returns true if there are unused mocks leftover

func (*MockRequestor) MarshalJSON added in v0.54.0

func (r *MockRequestor) MarshalJSON() ([]byte, error)

func (*MockRequestor) UnmarshalJSON added in v0.52.0

func (r *MockRequestor) UnmarshalJSON(data []byte) error

type MockResponse added in v0.52.0

type MockResponse struct {
	Status int    `json:"status" validate:"required"`
	Body   string `json:"body" validate:"required"`
}

func NewMockResponse

func NewMockResponse(status int, body string) MockResponse

NewMockResponse creates a new mock response

func (MockResponse) Make added in v0.52.0

func (m MockResponse) Make(request *http.Request) *http.Response

type Requestor

type Requestor interface {
	Do(*http.Client, *http.Request) (*http.Response, error)
}

Requestor is anything that can make an HTTP request with a client

var DefaultRequestor Requestor = defaultRequestor{}

DefaultRequestor is the default HTTP requestor

type Trace

type Trace struct {
	Request       *http.Request
	RequestTrace  []byte
	Response      *http.Response
	ResponseTrace []byte
	ResponseBody  []byte
	StartTime     time.Time
	EndTime       time.Time
}

Trace holds the complete trace of an HTTP request/response

func DoTrace

func DoTrace(client *http.Client, method string, url string, body io.Reader, headers map[string]string) (*Trace, error)

DoTrace makes the given request saving traces of the complete request and response

func (*Trace) String added in v0.52.0

func (t *Trace) String() string

Jump to

Keyboard shortcuts

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