request

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package request is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var NoopPreparer = PrepareFunc(func(req *http.Request) (*http.Request, error) { return req, nil })

Functions

func CopyURL

func CopyURL(i *url.URL) *url.URL

func OverrideURL

func OverrideURL(dst, src *url.URL)

func WriteJSON

func WriteJSON(req *http.Request, msg interface{}) error

Types

type BasicAuthConfig

type BasicAuthConfig struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

type MockPreparer

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

MockPreparer is a mock of Preparer interface.

func NewMockPreparer

func NewMockPreparer(ctrl *gomock.Controller) *MockPreparer

NewMockPreparer creates a new mock instance.

func (*MockPreparer) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPreparer) Prepare

func (m *MockPreparer) Prepare(arg0 *http.Request) (*http.Request, error)

Prepare mock base method.

type MockPreparerMockRecorder

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

MockPreparerMockRecorder is the mock recorder for MockPreparer.

func (*MockPreparerMockRecorder) Prepare

func (mr *MockPreparerMockRecorder) Prepare(arg0 interface{}) *gomock.Call

Prepare indicates an expected call of Prepare.

type PrepareFunc

type PrepareFunc func(*http.Request) (*http.Request, error)

PrepareFunc is a method that implements the Preparer interface.

func (PrepareFunc) Prepare

func (f PrepareFunc) Prepare(r *http.Request) (*http.Request, error)

Prepare implements the Preparer interface on PrepareFunc.

type Preparer

type Preparer interface {
	Prepare(*http.Request) (*http.Request, error)
}

Preparer is the interface that allows to prepare a http.Request

Prepare accepts and possibly modifies a Request (e.g., adding Headers). Implementations must ensure to not share or hold per-invocation state since Preparers may be shared and re-used.

func BasicAuth

func BasicAuth(cfg *BasicAuthConfig) Preparer

BasicAuth sets Authorization header "Basic <username>:<password>" If header is already set then does nothing if User is set on request URL then set username, password to the values of the URL

func Body

func Body() Preparer

Body ensures that GetBody method is set on request

func CombinePreparer

func CombinePreparer(preparers ...Preparer) Preparer

CombinePreparer combines multiple preparers into a single one

func ExtractURI

func ExtractURI(reset bool) Preparer

ExtractURI parses request URI, updates request URL and optional reset URI

func ForwardedFor

func ForwardedFor() Preparer

ForwardedFor populates "X-Forwarded-For" header with the client IP address In case, "X-Forwarded-For" was already populated (e.g. if we are not the first proxy) then retains prior X-Forwarded-For information as a comma+space separated list and fold multiple headers into one.

func HTTPProtocol

func HTTPProtocol(major, minor int) Preparer

HTTPProtocol sets HTTP protocol on request

Example: HTTP/1.1 or HTTP/2.

func Headers

func Headers(overrides map[string][]string) Preparer

Headers sets or deletes custom request headers

func HeadersPreparer

func HeadersPreparer(h func(http.Header) error) Preparer

func Host

func Host(host *string) Preparer

Host set request Host This is useful when proxying request (to set the request host to match downstream server) If host is nil then it sets the Host to request URL host

func Proxy

func Proxy(cfg *ProxyConfig) (Preparer, error)

Proxy creates a preparer for proxying request

func RemoveConnectionHeaders

func RemoveConnectionHeaders() Preparer

RemoveConnectionHeaders removes "Connection" header See RFC 7230, section 6.1

func RemoveHopByHopHeaders

func RemoveHopByHopHeaders() Preparer

RemoveHopByHopHeaders remove Hop-by-hop headers from the request These headers are meaningful only for a single transport-level connection, and must not be retransmitted by proxies or cached (c.f. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers)

func Request

func Request(baseReq *http.Request) Preparer

Request is a preparer that enhance req with baseReq fields

func URL

func URL(u *url.URL) Preparer

URL set request URL to the passed URL

func UserAgent

func UserAgent(agent string) Preparer

UserAgent sets User-Agent header

type ProxyConfig

type ProxyConfig struct {
	Addr           string              `json:"addr,omitempty"`
	PassHostHeader *bool               `json:"passHostHeader,omitempty"`
	BasicAuth      *BasicAuthConfig    `json:"basicAuth,omitempty"`
	Headers        map[string][]string `json:"headers,omitempty"`
}

func (*ProxyConfig) SetDefault

func (cfg *ProxyConfig) SetDefault() *ProxyConfig

Jump to

Keyboard shortcuts

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