httplab

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: MIT Imports: 12 Imported by: 5

README

HTTPLAB

Build Status Go Report Card PRs Welcome

The interactive web server.

HTTPLabs let you inspect HTTP requests and forge responses.


screencast

Install

Golang
go get github.com/gchaincl/httplab
go install github.com/gchaincl/httplab/cmd/httplab
Archlinux
yaourt httplab
Snap FIXME

On systems where snap is supported:

snap install httplab
Binary distribution

Each release provides pre-built binaries for different architectures, you can download them here: https://github.com/gchaincl/httplab/releases/latest

Help

Usage of httplab:
  -a, --auto-update       Auto-updates response when fields change. (default true)
  -b, --body string       Specifies the inital response body. (default "Hello, World")
  -c, --config string     Specifies custom config path.
      --cors              Enable CORS.
      --cors-display      Display CORS requests. (default true)
  -d, --delay int         Specifies the initial response delay in ms.
  -H, --headers strings   Specifies the initial response headers. (default [X-Server:HTTPLab])
  -p, --port int          Specifies the port where HTTPLab will bind to. (default 10080)
  -s, --status string     Specifies the initial response status. (default "200")
  -v, --version           Prints current version.
Key Bindings
Key Description
Tab Next Input
Shift+Tab Previous Input
Ctrl+a Apply Response changes
Ctrl+r Resets Request history
Ctrl+s Save Response as
Ctrl+f Save Request as
Ctrl+l Toggle Responses list
Ctrl+t Toggle Response builder
Ctrl+o Open Body file
Ctrl+b Switch Body mode
Ctrl+h Toggle Help
Ctrl+w Toggle line wrapping
q Close popup
PgUp Previous Request
PgDown Next Request
Ctrl+c Quit

HTTPLab uses file to store pre-built responses, it will look for a file called .httplab on the current directory if not found it will fallback to $HOME. A sample file can be found here.

HTTPLab is heavily inspired by wuzz

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decolorize added in v0.3.0

func Decolorize(s []byte) []byte

Decolorize remove the color escape sequences from a []byte encoded string

func DumpRequest

func DumpRequest(req *http.Request) ([]byte, error)

DumpRequest pretty prints an http.Request

func ExpandPath added in v0.2.0

func ExpandPath(path string) string

ExpandPath expands a given path by replacing '~' with $HOME of the current user.

Types

type Body added in v0.2.0

type Body struct {
	Mode  BodyMode
	Input []byte
	File  *os.File
}

Body is our response body content, that will either reference an local file or a runtime-supplied []byte.

func (*Body) Info added in v0.2.0

func (body *Body) Info() []byte

Info returns some basic info on the body.

func (*Body) Payload added in v0.2.0

func (body *Body) Payload() []byte

Payload reads out a []byte payload according to it's configuration in Body.BodyMode.

func (*Body) SetFile added in v0.2.0

func (body *Body) SetFile(path string) error

SetFile set a new source file for the body, if it exists.

type BodyMode added in v0.2.0

type BodyMode uint

BodyMode represent the current Body mode

const (
	// BodyInput takes the body input from input box
	BodyInput BodyMode = iota + 1
	// BodyFile takes  the body input from a file
	BodyFile
)

func (BodyMode) String added in v0.2.0

func (m BodyMode) String() string

String to satisfy interface fmt.Stringer

type Response

type Response struct {
	Status  int
	Headers http.Header
	Body    Body
	Delay   time.Duration
}

Response is the the preconfigured HTTP response that will be returned to the client.

func NewResponse

func NewResponse(status, headers, body string) (*Response, error)

NewResponse configures a new response. An empty status will be interpreted as 200 OK.

func (*Response) MarshalJSON

func (r *Response) MarshalJSON() ([]byte, error)

MarshalJSON serializes the response into a JSON []byte.

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(data []byte) error

UnmarshalJSON inflates the Response from []byte representing JSON.

func (*Response) Write

func (r *Response) Write(w http.ResponseWriter) error

Write flushes the body into the ResponseWriter, hence sending it over the wire.

type ResponsesList added in v0.3.0

type ResponsesList struct {
	List map[string]*Response
	// contains filtered or unexported fields
}

ResponsesList holds the multiple configured responses.

func NewResponsesList added in v0.3.0

func NewResponsesList() *ResponsesList

NewResponsesList creates a new empty response list and returns it.

func (*ResponsesList) Add added in v0.3.0

func (rl *ResponsesList) Add(key string, r *Response) *ResponsesList

Add appends a response item to the list. You need to supply a key for the item.

func (*ResponsesList) Cur added in v0.3.0

func (rl *ResponsesList) Cur() *Response

Cur retrieves the current response from the response list.

func (*ResponsesList) Del added in v0.3.0

func (rl *ResponsesList) Del(key string) bool

Del removes an item spceified by its key from the response list. It returns false if the item didn't exist at all.

func (*ResponsesList) Get added in v0.3.0

func (rl *ResponsesList) Get(key string) *Response

Get retrieves a specific response by name from the response list.

func (*ResponsesList) Index added in v0.3.0

func (rl *ResponsesList) Index() int

Index retrieves the index of the current item in the response list.

func (*ResponsesList) Keys added in v0.3.0

func (rl *ResponsesList) Keys() []string

Keys retrieves an []string of all keys in the response list.

func (*ResponsesList) Len added in v0.3.0

func (rl *ResponsesList) Len() int

Len reports the length of the response list.

func (*ResponsesList) Load added in v0.3.0

func (rl *ResponsesList) Load(path string) error

Load loads a response list from a local JSON document.

func (*ResponsesList) Next added in v0.3.0

func (rl *ResponsesList) Next()

Next iterates to the next item in the response list.

func (*ResponsesList) Prev added in v0.3.0

func (rl *ResponsesList) Prev()

Prev iterates to the previous item in the response list.

func (*ResponsesList) Save added in v0.3.0

func (rl *ResponsesList) Save(path string) error

Save saves the current response list to a JSON document on local disk.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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