httplab

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: MIT Imports: 12 Imported by: 0

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

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

func ExpandPath(path string) string

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

Types

type Body

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

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

Info returns some basic info on the body.

func (*Body) Payload

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

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

func (*Body) SetFile

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

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

type BodyMode

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

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

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

ResponsesList holds the multiple configured responses.

func NewResponsesList

func NewResponsesList() *ResponsesList

NewResponsesList creates a new empty response list and returns it.

func (*ResponsesList) Add

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

func (rl *ResponsesList) Cur() *Response

Cur retrieves the current response from the response list.

func (*ResponsesList) Del

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

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

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

func (*ResponsesList) Index

func (rl *ResponsesList) Index() int

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

func (*ResponsesList) Keys

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

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

func (*ResponsesList) Len

func (rl *ResponsesList) Len() int

Len reports the length of the response list.

func (*ResponsesList) Load

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

Load loads a response list from a local JSON document.

func (*ResponsesList) Next

func (rl *ResponsesList) Next()

Next iterates to the next item in the response list.

func (*ResponsesList) Prev

func (rl *ResponsesList) Prev()

Prev iterates to the previous item in the response list.

func (*ResponsesList) Save

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

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

Directories

Path Synopsis
cmd
httplab command

Jump to

Keyboard shortcuts

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