intercept

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRequestAborted   = errors.New("intercept: request was aborted")
	ErrRequestNotFound  = errors.New("intercept: request not found")
	ErrRequestDone      = errors.New("intercept: request is done")
	ErrResponseNotFound = errors.New("intercept: response not found")
)

Functions

func MatchRequestFilter

func MatchRequestFilter(req *http.Request, expr search.Expression) (bool, error)

MatchRequestFilter returns true if an HTTP request matches the request filter expression.

func MatchRequestScope

func MatchRequestScope(req *http.Request, s *scope.Scope) (bool, error)

func MatchResponseFilter

func MatchResponseFilter(res *http.Response, expr search.Expression) (bool, error)

MatchResponseFilter returns true if an HTTP response matches the response filter expression.

func ShouldInterceptResponseFromContext

func ShouldInterceptResponseFromContext(ctx context.Context) (bool, bool)

func WithInterceptResponse

func WithInterceptResponse(ctx context.Context, value bool) context.Context

Types

type Config

type Config struct {
	Logger           log.Logger
	RequestsEnabled  bool
	ResponsesEnabled bool
	RequestFilter    search.Expression
	ResponseFilter   search.Expression
}

type Item

type Item struct {
	Request  *http.Request
	Response *http.Response
}

type Request

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

Request represents a server received HTTP request, alongside a channel for sending a modified version of it to the routine that's awaiting it. Also contains a channel for receiving a cancellation signal.

type RequestIDs

type RequestIDs []ulid.ULID

RequestIDs implements sort.Interface.

func (RequestIDs) Len

func (ids RequestIDs) Len() int

func (RequestIDs) Less

func (ids RequestIDs) Less(i, j int) bool

func (RequestIDs) Swap

func (ids RequestIDs) Swap(i, j int)

type Response

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

Response represents an HTTP response from a proxied request, alongside a channel for sending a modified version of it to the routine that's awaiting it. Also contains a channel for receiving a cancellation signal.

type Service

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

func NewService

func NewService(cfg Config) *Service

func (*Service) CancelRequest

func (svc *Service) CancelRequest(reqID ulid.ULID) error

CancelRequest ensures an intercepted request is dropped.

func (*Service) CancelResponse

func (svc *Service) CancelResponse(reqID ulid.ULID) error

CancelResponse ensures an intercepted response is dropped.

func (*Service) ClearRequests

func (svc *Service) ClearRequests()

func (*Service) ClearResponses

func (svc *Service) ClearResponses()

func (*Service) InterceptRequest

func (svc *Service) InterceptRequest(ctx context.Context, req *http.Request) (*http.Request, error)

InterceptRequest adds an HTTP request to an array of pending intercepted requests, alongside channels used for sending a cancellation signal and receiving a modified request. It's safe for concurrent use.

func (*Service) InterceptResponse

func (svc *Service) InterceptResponse(ctx context.Context, res *http.Response) (*http.Response, error)

InterceptResponse adds an HTTP response to an array of pending intercepted responses, alongside channels used for sending a cancellation signal and receiving a modified response. It's safe for concurrent use.

func (*Service) ItemByID

func (svc *Service) ItemByID(id ulid.ULID) (Item, error)

ItemByID returns an intercepted item (request and possible response) by ID. It's safe for concurrent use.

func (*Service) Items

func (svc *Service) Items() []Item

Items returns a list of pending items (requests and responses). It's safe for concurrent use.

func (*Service) ModifyRequest

func (svc *Service) ModifyRequest(reqID ulid.ULID, modReq *http.Request, modifyResponse *bool) error

ModifyRequest sends a modified HTTP request to the related channel, or returns ErrRequestDone when the request was cancelled. It's safe for concurrent use.

func (*Service) ModifyResponse

func (svc *Service) ModifyResponse(reqID ulid.ULID, modRes *http.Response) error

ModifyResponse sends a modified HTTP response to the related channel, or returns ErrRequestDone when the related request was cancelled. It's safe for concurrent use.

func (*Service) RequestModifier

func (svc *Service) RequestModifier(next proxy.RequestModifyFunc) proxy.RequestModifyFunc

RequestModifier is a proxy.RequestModifyMiddleware for intercepting HTTP requests.

func (*Service) ResponseModifier

func (svc *Service) ResponseModifier(next proxy.ResponseModifyFunc) proxy.ResponseModifyFunc

ResponseModifier is a proxy.ResponseModifyMiddleware for intercepting HTTP responses.

func (*Service) UpdateSettings

func (svc *Service) UpdateSettings(settings Settings)

type Settings

type Settings struct {
	RequestsEnabled  bool
	ResponsesEnabled bool
	RequestFilter    search.Expression
	ResponseFilter   search.Expression
}

Jump to

Keyboard shortcuts

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