Skip to content
uolePublic

About

Capture and parse http traffics

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Latest commit

 

History

23 Commits

Folders and files

Repository files navigation

httpcap

License: MIT

Parse and display HTTP traffic from a network device or a saved pcap file. This is a Go implementation of the original pcap-parser, built on top of the gopacket project.

Dependency

httpcap uses libpcap, a system-independent interface for user-level packet capture. Install libpcap before using httpcap.

For Ubuntu/Debian:

sudo apt install libpcap-dev

For CentOS/RHEL/Fedora:

sudo yum install libpcap-devel

For macOS:

brew install libpcap

Live packet capture may require elevated privileges.

Installation

go install github.com/uole/httpcap/cmd/httpcap@latest

Usage

Usage of httpcap:
  -f string
        BPF filter in libpcap filter syntax
  -host string
        filter HTTP request host, using wildcard match (*)
  -i string
        name or index of interface
  -ip string
        filter source or target IP
  -l
        list interfaces and exit
  -p int
        filter source or target port
  -pprof
        enable the HTTP debug server on 127.0.0.1:8080
  -r string
        read packets from a pcap file
  -v
        display version info and exit

When -pprof is enabled, pprof endpoints are available at http://127.0.0.1:8080/debug/pprof/. The debug server is not exposed on external interfaces.

An explicit -f BPF expression is combined with the generated tcp, -p, and -ip conditions using and.

Protocol support and limits

  • HTTP/1.0 and HTTP/1.1 are supported, including Content-Length, chunked request/response bodies, trailers, informational responses, HEAD, 204, 304, and upgrade handshakes.
  • Only the chunked transfer coding is decoded. Other transfer codings are rejected instead of being parsed with incorrect message boundaries.
  • Each request/response body is limited to 16 MiB. Oversized messages are dropped to avoid unbounded memory use.
  • The TUI retains at most 2,000 HTTP exchanges/WebSocket frames and approximately 256 MiB of retained message data; older entries are evicted automatically.
  • At most 128 HTTP streams are parsed concurrently; additional HTTP streams are closed until a slot is available.
  • Cleartext WebSocket (ws://) handshakes and RFC 6455 frames are decoded, including text/binary data, fragmentation, Ping/Pong, and Close. Frames are limited to 1 MiB and reassembled messages to 4 MiB.
  • permessage-deflate, wss://, and CONNECT tunnel bytes are not decoded yet.
  • A connection first observed at an HTTP response is dropped because the original request method and message boundary cannot be determined safely.
  • Classic pcap files are supported through -r; pcapng support depends on the installed libpcap.
  • Offline analysis does not require elevated privileges. At EOF, the TUI reports PCAP done and remains open for browsing and export.
  • TLS traffic, HTTP/2, and HTTP/3 are not supported.

Example

List interfaces:

httpcap -l

Capture HTTP traffic:

sudo httpcap -i eth0

Filter by HTTP host:

sudo httpcap -i eth0 -host '*.example.com'

Host matching is case-insensitive, ignores an explicit port, and supports IPv6 literals. Without -host, valid HTTP/1.0 requests that omit the Host header are also captured.

Analyze a saved capture:

httpcap -r capture.pcap
httpcap -r capture.pcap -host '*.example.com'
httpcap -r capture.pcap -p 8080 -f 'tcp port 8080'

-r and -i are mutually exclusive. Offline mode uses the same BPF, TCP reassembly, HTTP parsing, filtering, and retention limits as live capture. If the file cannot be read to completion, the TUI reports PCAP error with the underlying error.

Interactive features

The request list shows a stable exchange ID, method, response status, observed duration, and request URI. Incomplete responses, timeouts, malformed messages, and streams that exceed the concurrent-stream limit are shown as ERROR rows instead of being silently discarded. WebSocket frames appear as WS rows with direction, opcode, payload size, and request URI.

Key Action
Tab Switch focus between the request list and HTTP content
Space Toggle the body preview between 16 KiB and 256 KiB
1 / 2 / 0 Show request / response / both
f Toggle JSON, XML, and form body formatting
/ Search and filter retained exchanges
e Export the selected HTTP exchange or WebSocket frame
F5 Clear retained history
F6 Pause or resume capturing
Ctrl+C Exit

Search terms are combined with AND and matched case-insensitively. Free text searches request metadata; typed terms can target specific fields:

method:post status:4xx host:example.com path:/v1
header:content-type=json body:marvin
opcode:text direction:send body:subscribe

status:4xx matches an entire status class. Body search inspects at most the first 64 KiB of each body. WebSocket rows can be filtered with opcode:text, opcode:ping, direction:send, or direction:recv.

Press e and enter a destination path. The extension selects the format:

  • .json: complete semantic HTTP exchange or WebSocket frame, including metadata and body/payload
  • .har: HAR 1.2 for HTTP exchanges, suitable for importing into browser developer tools
  • .curl or .sh: a curl command for HTTP request bodies

WebSocket frames support JSON export only. An empty path writes httpcap-<id>.json for an HTTP exchange or httpcap-ws-<id>.json for a WebSocket frame in the current directory. Exported files are created with owner-only permissions because HTTP headers and bodies may contain credentials or personal data. Binary request bodies are omitted from curl output with an explanatory comment; use JSON or HAR to preserve them.

Body formatting works for JSON, XML, and application/x-www-form-urlencoded. JSON/XML text WebSocket payloads are also formatted when detected. Rendering is bounded for both request/response bodies and WebSocket payloads; exports always contain the complete captured body/payload.

httpcap

Development

make build     # build bin/httpcap
make test      # run tests
make test-race # run tests with the race detector
make vet       # run go vet
make fmt      # format Go sources

About

Capture and parse http traffics

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages