httpdump

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2022 License: MIT Imports: 11 Imported by: 0

README

http-dump

A HTTP Dev Server to dump request

Support h2, h2c

Installation

go install github.com/maruware/http-dump/cmd/http-dump

or Download from Releases

Usage

Quick
$ http-dump
Listening http://0.0.0.0:8080...
2022/02/05 15:44:26 GET /sample HTTP/1.1 # curl http://localhost:8080/sample
2022/02/05 15:44:51 GET /sample HTTP/2.0 # curl --http2-prior-knowledge http://localhost:8080/sample
$ http-dump -o json
Listening http://0.0.0.0:8080...
2022/02/05 15:57:26 {"method":"POST","path":"/sample","is_tls":false,"body":"hello","header":{"Accept":["*/*"],"Content-Length":["5"],"Content-Type":["application/x-www-form-urlencoded"],"User-Agent":["curl/7.77.0"]},"protocol":"HTTP/2.0"} # curl --http2-prior-knowledge http://localhost:8080/sample -d hello
Options
$ http-dump -h
NAME:
   http-dump - http dump dev server

USAGE:
   http-dump [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --port value, -p value    listen port (default: 8080)
   --bind value, -b value    listen ip (default: "0.0.0.0")
   --cert value              TLS cert file path
   --key value               TLS key file path
   --output value, -o value  output format (simple or json or simple_color) (default: "simple_color")
   --help, -h                show help (default: false)
h2 (https)

Prepare cert

$ go run $(go env GOROOT)/src/crypto/tls/generate_cert.go -rsa-bits 2048 -host localhost
2022/02/05 15:50:18 wrote cert.pem
2022/02/05 15:50:18 wrote key.pem
$ http-dump --cert ./cert.pem --key ./key.pem
Listening https://0.0.0.0:8080...
2022/02/05 15:53:56 GET /sample HTTP/2.0 # curl --http2 --insecure https://localhost:8080/sample

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(opts ServeOpts) error

Types

type Handler

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

func NewHandler

func NewHandler(format string) *Handler

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Logger

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

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

type RequestSummary

type RequestSummary struct {
	Time     time.Time   `json:"time"`
	Method   string      `json:"method"`
	Path     string      `json:"path"`
	IsTLS    bool        `json:"is_tls"`
	Body     string      `json:"body"`
	Header   http.Header `json:"header"`
	Protocol string      `json:"protocol"`
}

type ServeOpts

type ServeOpts struct {
	Port   int
	Ip     string
	Cert   string
	Key    string
	Format string
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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