Documentation
¶
Overview ¶
Package httpwatcher traces outbound HTTP requests made by Go processes. It attaches Linux uprobes to net/http.(*Client).do using eBPF. The events returned are a subset of the original http.Request, with truncated strings and headers.
Basic usage:
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
snoop, err := httpwatcher.Init(ctx)
if err != nil { ... }
defer snoop.Close()
if err := snoop.Attach(pid); err != nil { ... }
for ev := range snoop.Events() {
fmt.Printf("%d %s %s\n", ev.PID, ev.Method, ev.URL)
for k, v := range ev.Headers {
fmt.Printf(" %s: %s\n", k, v)
}
}
Example ¶
Example output for a process making requests:
1234 GET https://192.168.100.55:8888/v1/users Authorization: Bearer XXXX Accept: application/json
package main
import (
"context"
"fmt"
"log"
"os/signal"
"syscall"
"github.com/jamessanford/httpwatcher"
)
func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
snoop, err := httpwatcher.Init(ctx)
if err != nil {
log.Fatal(err)
}
defer snoop.Close()
pid := 1234
if err := snoop.Attach(pid); err != nil {
log.Fatal(err)
}
for ev := range snoop.Events() {
fmt.Printf("%d %s %s\n", ev.PID, ev.Method, ev.URL)
for k, v := range ev.Headers {
fmt.Printf(" %s: %s\n", k, v)
}
}
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPEvent ¶
type HTTPEvent struct {
PID int // PID of the process that issued the request
Method string // HTTP method (e.g. "GET", "POST")
URL string // Reconstructed URL; each component truncated to 64 bytes
Headers map[string]string // Request headers; at most 16 entries, keys ≤64 bytes, values ≤512 bytes
}
HTTPEvent is an outbound HTTP request captured from an instrumented process.
type Snooper ¶
type Snooper struct {
// contains filtered or unexported fields
}
Snooper manages uprobe-based HTTP request interception for multiple processes.
func Init ¶
Init loads the uprobe BPF program and starts the event loop. The returned Snooper delivers events until ctx is cancelled or Close() is called, after which the Events channel is closed and all uprobe links are released.
func (*Snooper) Attach ¶
Attach installs an HTTP uprobe on the process with the given PID. It reads the binary's build info to verify Go version compatibility and resolve struct field offsets.