apis

package
v0.0.0-...-22661af Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: GPL-3.0 Imports: 5 Imported by: 4

README

WHY

This package is meant to be a lightweight package that both the gopherjs-based UI and the backend can import to share communication constants.

It is a separate, stand-alone, lightweight package to avoid compiling big parts of the frontend in the backend.

One more reason to keep these constants all together is to make it easier to build alternative UIs for wapty and to understand which functionalities are exposed by the websocket api.

Documentation

Index

Constants

View Source
const (

	// EDT_FORWARD tells the backend to forward the currently intercepted request/response
	EDT_FORWARD Action = "forward"
	// EDT_EDIT tells the backend to forward the provided payload instead of the original one
	EDT_EDIT = "edit"
	// EDT_DROP tells the backend to create a dummy response and send it to the client.
	// If a request is dropped it won't be forwarded to the server.
	EDT_DROP = "drop"
	// EDT_PROVIDERESP only has meaning if a request was intercepted. It allows to
	// provide a response to the current request without forwarding it to the server.
	EDT_PROVIDERESP = "provideResp"

	// HST_DUMP dumps the entire status, this is for debug purposes only
	HST_DUMP = "dump"
	// HST_FILTER allows to search and filter through history
	HST_FILTER = "filter"
	// HST_FETCH return the ReqResp given an ID
	HST_FETCH = "fetch"
	// HST_METADATA returns the metadata for the given ID
	HST_METADATA = "metaData"

	// RPT_CREATE Creates a new repeater entry
	RPT_CREATE = "create"
	// RPT_GO Performs the request
	RPT_GO = "go"
	// RPT_GET Retrieves an history item
	RPT_GET = "get"

	// STN_INTERCEPT Gets (no params) or sets (param "ON") the intercept status
	STN_INTERCEPT = "intercept"
)
View Source
const (

	// PLD_REQUEST should be used to tell the UI if the payload is a request
	PLD_REQUEST = "request"
	// PLD_RESPONSE should be used to tell the UI if the payload is a response
	PLD_RESPONSE = "response"
)
View Source
const (
	// ARG_ID is used to identify which item of the collection should be fetched
	ARG_ID ArgName = "id"
	// ARG_SUBID is used to identify which item of the collection should be fetched.
	// This is applied only if the resource identified by ID contains a collection.
	ARG_SUBID = "subId"
	// ARG_PAYLOADTYPE is used by editor to distinguish between requests and responses.
	ARG_PAYLOADTYPE = "payloadType"
	// ARG_ENDPOINT is used to refer to the host:port or schema://host:port
	ARG_ENDPOINT = "endpoint"
	// ARG_ERR is a value used to communicate an error occourred
	ARG_ERR = "error"
	// ARG_TLS is used as a bool to tell if ARG_TLS must be used for the specified operation
	ARG_TLS = "tls"
	// ARG_TRUE is used to deserialize a bool from a string.
	ARG_TRUE = "true"
	// ARG_FALSE is used to deserialize a bool from a string.
	ARG_FALSE = ""
	// ARG_ON is used as a key value for togglable settings
	ARG_ON = "on"
)
View Source
const (
	// CHN_EDITOR channel used by intercept package, editor actions
	CHN_EDITOR UIChannel = "proxy/intercept/editor"
	// CHN_HISTORY channel used by intercept package, history actions
	CHN_HISTORY = "proxy/httpHistory"
	// CHN_REPEAT channel used by repeat package
	CHN_REPEAT = "repeat"
	// CHN_INTERCEPTSETTINGS channel used by intercept package, history actions
	CHN_INTERCEPTSETTINGS = "proxy/intercept/options"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action is a string representing the action to perform

type ArgName

type ArgName string

ArgName is the type of the set of Keys to use in the Args map of a command

type Command

type Command struct {
	Channel UIChannel
	Action  Action
	Args    map[ArgName]string
	Payload []byte
}

Command represents a packet of information sent or received by or from the server.

func Err

func Err(m interface{}) *Command

Err returns a command that contains the error message as argument and ERR as action

func (*Command) PackArgs

func (cmd *Command) PackArgs(names []ArgName, vars ...string)

PackArgs is used to set the value of the arguments of a command.

WARNING: this function PANICS if len(names) != len(vars) since that surely means there is a bug in the code.

func (*Command) UnpackArgs

func (cmd *Command) UnpackArgs(names []ArgName, vars ...interface{}) (err error)

UnpackArgs is used to extract the value of the arguments from a command. cmd is the command to extract the values from, names is a list of ArgName that is used to access cmd.Args. vars can be pointers to either int, bool or string. This function will attempt to deserialize the arguments with the proper type and operations in order to fit the given vars types.

WARNING: this function PANICS if len(names) != len(vars) since that surely means there is a bug in the code.

type ReqResp

type ReqResp struct {
	//Unique ID in the history
	ID int
	//Meta Data about both Req and Resp
	MetaData *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 create a test that fails if this is different from intercept.ReqResp

type ReqRespMetaData

type ReqRespMetaData struct {
	ID          int
	Host        string
	Method      string
	Path        string
	Params      bool
	Edited      bool
	Status      string
	Length      int64
	ContentType string
	Extension   string
	TLS         bool
	IP          string
	Port        string
	Cookies     string
	Time        string
}

ReqRespMetaData is a wrapper type to hold all metadata on a status ReqResp

type UIChannel

type UIChannel string

UIChannel is a string used to multiplex on the websocket and route commands to the proper packages

Jump to

Keyboard shortcuts

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