httpbaseline

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	URL     string              `json:"url"`
	Method  string              `json:"method"`
	Headers map[string][]string `json:"headers"`

	// Right now we assume that the body is text
	Body string `json:"body"`
}

Request represents an http.Request that we can store on disk.

func NewRequest

func NewRequest(r *http.Request) (*Request, error)

NewRequest creates a new Request object, excluding certain headers. It returns an error if there is an issue reading from the body or closing the body.

func ReadRequestFromFile

func ReadRequestFromFile(path string) (Request, error)

ReadRequestFromFile reads a Request from a file and returns it, or an error if the file cannot be read or the Request cannot be unmarshalled.

func (Request) ToTestRequest

func (req Request) ToTestRequest(ctx context.Context) *http.Request

ToTestRequest converts the given request object into an http-test-request.

type Response

type Response struct {
	StatusCode int                 `json:"statusCode"`
	Headers    map[string][]string `json:"headers"`

	// Right now we assume that the body is text
	Body string `json:"body"`
}

Response represents an http.Response that we can store on disk.

func NewResponse

func NewResponse(r *http.Response) (*Response, error)

NewResponse creates a new Response object, excluding certain headers. It returns an error if there is an issue reading from the body or closing it.

func ReadResponseFromFile

func ReadResponseFromFile(path string) (Response, error)

ReadResponseFromFile reads a Response from a file at the given path and returns it, or an error if the file could not be read or the Response could not be unmarshalled.

func (Response) CreateRoundTripper

func (res Response) CreateRoundTripper() *RoundTripper

CreateRoundTripper creates a RoundTripper instance with the Response instance as its Response field.

type RoundTripper

type RoundTripper struct {
	Request  Request
	Response Response
}

RoundTripper is a single-use http.RoundTripper implementation that can capture a request and produces a pre-configured response.

func (*RoundTripper) RoundTrip

func (rt *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip captures and responds to a request, setting the response headers and body from the request, returning an error if one occurs.

Jump to

Keyboard shortcuts

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