intercept

package
v0.0.0-...-7fb543b Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2017 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package intercept is meant to handle all the interception of requests and responses, including stopping and waiting for edited payloads. Every request going through the proxy is parsed and added to the Status by this package.

Index

Constants

This section is empty.

Variables

View Source
var HopByHopHeaders = []string{
	"Content-Encoding",
	"Connection",
	"TE",
	"HTTP2-Settings",
	"Keep-Alive",
	"Proxy-Authenticate",
	"Proxy-Connection",
	"Proxy-Authorization",
	"Trailer",
	"Upgrade",
	"Transfer-Encoding",
	"Alternate-Protocol",
	"X-Forwarded-For",
	"Proxy-Connection",
}

HopByHopHeaders is a list of all the HTTP headers that are stripped away by the proxy

View Source
var RequestQueue chan *pendingRequest

RequestQueue represents the queue of requests that have been intercepted

View Source
var ResponseQueue chan *pendingResponse

ResponseQueue represents the queue of the response to requests that have been intercepted

Functions

func GenerateResponse

func GenerateResponse(title, content string, status int) *http.Response

GenerateResponse creates a response with a given title, content and status code. This can be used for example to provide responses when a request is dropped and do not leave the client hanging.

func MainLoop

func MainLoop()

MainLoop is the core of the interceptor. In order for the normal lifecycle program to work this should always be started. It starts the goroutine that waits for new requests and response that have been intercepted and takes action based on current configuration.

func StatusDump

func StatusDump(status *History)

StatusDump dumps the status in the log. This is only meant for debug purposes.

Types

type History

type History struct {
	sync.RWMutex `json:"-"`
	//Remove count, use it only for serialization
	Count    int
	ReqResps []*ReqResp
}

History is used to represent all the req/resp that went through the proxy FIXME!!! implement high-level methods!!! FIXME make the fields private and create a dummy object to transmit this

func GetStatus

func GetStatus() *History

GetStatus returns the current status

func (*History) Load

func (h *History) Load(in io.Reader) error

Load loads the status from a json formatted stream

func (*History) Save

func (h *History) Save(out io.Writer) error

Save saves the status in a json formatted stream

func (*History) String

func (h *History) String() string

String returns the name of the current package/project

type Interceptor

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

Interceptor is a struct that respects the net.RoundTripper interface and just wraps the original http.RoundTripper

func (*Interceptor) RoundTrip

func (ri *Interceptor) RoundTrip(req *http.Request) (res *http.Response, err error)

RoundTrip is a mock RoundTrip used to intercept requests and responses before they are forwarded by the proxy.

type ReqResp

type ReqResp struct {
	//Unique ID in the history
	ID int
	//Meta Data about both Req and Resp
	MetaData *apis.ReqRespMetaData
	//Original Request
	RawReq []byte
	//Original Response
	RawRes []byte
	//Edited Request
	RawEditedReq []byte
	//Edited Response
	RawEditedRes []byte
}

ReqResp represents an item of the proxy history TODO methods to parse req-resp TODO create a test that fails if this is different from apis.ReqResp

Jump to

Keyboard shortcuts

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