bridge

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 20 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyWithBufferPool

func CopyWithBufferPool(source io.Reader, destination io.Writer, pool httputil.BufferPool) (int64, error)

CopyBuffer copies bytes from passed in source to destination with provided pool

func HttpFileRecorder

func HttpFileRecorder(directory string, printStdOut bool) func(request *http.Request, response *http.Response)

HttpFileRecorder returns http route listener that will record request response to the passed in directory

func NewBytesBufferPool

func NewBytesBufferPool(poolSize, bufferSize int) httputil.BufferPool

NewBytesBufferPool returns new httputil.BufferPool pool.

func NewProxyHandler

func NewProxyHandler(proxyConfig *HttpBridgeProxyConfig, route *HttpBridgeProxyRoute) (http.Handler, error)

NewProxyHandler creates a new proxy handler

func NewProxyRecordingHandler

func NewProxyRecordingHandler(proxyConfig *HttpBridgeProxyConfig, route *HttpBridgeProxyRoute) (http.Handler, error)

func ReaderAsText

func ReaderAsText(reader io.Reader) string

Types

type HttpBridge

type HttpBridge struct {
	Config   *HttpBridgeConfig
	Server   *http.Server
	Handlers map[string]http.Handler
}

HttpBridge represents http bridge

func NewHttpBridge

func NewHttpBridge(config *HttpBridgeConfig, factory HttpBridgeProxyHandlerFactory) (*HttpBridge, error)

NewHttpBridge creates a new instance of NewHttpBridge

func StartRecordingBridge

func StartRecordingBridge(port string, outputDirectory string, routes ...*HttpBridgeProxyRoute) (*HttpBridge, error)

StartRecordingBridge start recording bridge proxy

func (*HttpBridge) ListenAndServe

func (r *HttpBridge) ListenAndServe() error

ListenAndServe start http endpoint

func (*HttpBridge) ListenAndServeTLS

func (r *HttpBridge) ListenAndServeTLS(certFile, keyFile string) error

ListenAndServe start http endpoint on secure port

type HttpBridgeConfig

type HttpBridgeConfig struct {
	Endpoint *HttpBridgeEndpointConfig
	Proxy    *HttpBridgeProxyConfig
	Routes   []*HttpBridgeProxyRoute
}

HttpBridgeConfig represents HttpBridgeConfig config

type HttpBridgeEndpointConfig

type HttpBridgeEndpointConfig struct {
	Port           string
	ReadTimeoutMs  int
	WriteTimeoutMs int
	MaxHeaderBytes int
}

HttpBridgeConfig represent http bridge config

type HttpBridgeProxyConfig

type HttpBridgeProxyConfig struct {
	MaxIdleConnections    int
	RequestTimeoutMs      int
	KeepAliveTimeMs       int
	TLSHandshakeTimeoutMs int
	BufferPoolSize        int
	BufferSize            int
}

HttpBridgeProxyConfig represent proxy config

type HttpBridgeProxyHandlerFactory

type HttpBridgeProxyHandlerFactory func(proxyConfig *HttpBridgeProxyConfig, route *HttpBridgeProxyRoute) (http.Handler, error)

ProxyHandlerFactory proxy handler factory

type HttpBridgeProxyRoute

type HttpBridgeProxyRoute struct {
	Pattern          string
	TargetURL        *url.URL
	ResponseModifier func(*http.Response) error
	Listener         func(request *http.Request, response *http.Response)
}

HttpBridgeProxyRoute represent http proxy route

type HttpRequest

type HttpRequest struct {
	Method      string      `json:",omitempty"`
	URL         string      `json:",omitempty"`
	Header      http.Header `json:",omitempty"`
	Body        string      `json:",omitempty"`
	ThinkTimeMs int         `json:",omitempty"`
}

HttpRequest represents JSON serializable http request

func NewHTTPRequest

func NewHTTPRequest(method, url, body string, header http.Header) *HttpRequest

NewHTTPRequest create a new instance of http request

type HttpResponse

type HttpResponse struct {
	Code   int
	Header http.Header `json:",omitempty"`
	Body   string      `json:",omitempty"`
}

HttpResponse represents JSON serializable http response

type HttpTrip

type HttpTrip struct {
	Request *http.Request
	// contains filtered or unexported fields
}

HTTPTrip represents recorded round trip.

func (*HttpTrip) CloseNotify

func (w *HttpTrip) CloseNotify() <-chan bool

func (*HttpTrip) Flush

func (w *HttpTrip) Flush()

func (*HttpTrip) Header

func (w *HttpTrip) Header() http.Header

func (*HttpTrip) Response

func (w *HttpTrip) Response() *http.Response

func (*HttpTrip) Write

func (w *HttpTrip) Write(b []byte) (int, error)

func (*HttpTrip) WriteHeader

func (w *HttpTrip) WriteHeader(status int)

type ListeningTripHandler

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

ListeningTripHandler represents endpoint recording handler

func AsListeningTripHandler

func AsListeningTripHandler(handler http.Handler) *ListeningTripHandler

func NewListeningHandler

func NewListeningHandler(handler http.Handler, bufferPoolSize, bufferSize int, listener func(request *http.Request, response *http.Response)) *ListeningTripHandler

func (*ListeningTripHandler) Notify

func (h *ListeningTripHandler) Notify(roundTrip *HttpTrip)

func (ListeningTripHandler) ServeHTTP

func (h ListeningTripHandler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request)

type RecordedHttpTrip

type RecordedHttpTrip struct {
	Request  *HttpRequest
	Response *HttpResponse
}

RecordedHttpTrip represents a recorded http trip

func ReadRecordedHttpTrips

func ReadRecordedHttpTrips(directory string) ([]*RecordedHttpTrip, error)

ReadRecordedHttpTrips scans provided directory for bridge.HttpRequest-%v.json and bridge.HttpResponse-%v.json template pairs

func ReadRecordedHttpTripsWithTemplate added in v0.31.0

func ReadRecordedHttpTripsWithTemplate(directory string, requestTemplate, respTemplate string) ([]*RecordedHttpTrip, error)

ReadRecordedHttpTripsWithPrefix scans provided directory for request, response pairs

Jump to

Keyboard shortcuts

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