httptrace

package
v0.0.0-...-744ddd9 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package httptrace provides HTTP request tracing with redirect chain following, timing breakdown per hop, and header inspection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatResult

func FormatResult(r *TraceResult) string

FormatResult returns a human-readable string for the trace result.

Types

type Hop

type Hop struct {
	Number          int               `json:"number"`
	URL             string            `json:"url"`
	Method          string            `json:"method"`
	StatusCode      int               `json:"status_code"`
	Status          string            `json:"status"`
	Proto           string            `json:"protocol"`
	ContentLength   int64             `json:"content_length"`
	ContentType     string            `json:"content_type"`
	Location        string            `json:"location,omitempty"`
	ServerIP        string            `json:"server_ip,omitempty"`
	TLSVersion      string            `json:"tls_version,omitempty"`
	TLSCipher       string            `json:"tls_cipher,omitempty"`
	RequestHeaders  map[string]string `json:"request_headers"`
	ResponseHeaders map[string]string `json:"response_headers"`
	Timing          HopTiming         `json:"timing"`
	Error           string            `json:"error,omitempty"`
}

Hop represents a single step in the HTTP redirect chain.

type HopTiming

type HopTiming struct {
	DNSStart    time.Time     `json:"-"`
	DNSDone     time.Time     `json:"-"`
	DNSDuration time.Duration `json:"dns_duration"`

	ConnectStart    time.Time     `json:"-"`
	ConnectDone     time.Time     `json:"-"`
	ConnectDuration time.Duration `json:"connect_duration"`

	TLSStart    time.Time     `json:"-"`
	TLSDone     time.Time     `json:"-"`
	TLSDuration time.Duration `json:"tls_duration"`

	FirstByteTime time.Duration `json:"first_byte_time"`
	TotalTime     time.Duration `json:"total_time"`
}

HopTiming holds timing information for a single HTTP hop.

type TraceOptions

type TraceOptions struct {
	URL            string
	Method         string
	MaxRedirects   int
	Timeout        time.Duration
	FollowRedirect bool
	InsecureSkip   bool
	Headers        map[string]string
}

TraceOptions configures an HTTP trace operation.

func DefaultOptions

func DefaultOptions() TraceOptions

DefaultOptions returns sensible defaults.

type TraceResult

type TraceResult struct {
	Hops           []Hop         `json:"hops"`
	FinalURL       string        `json:"final_url"`
	FinalStatus    int           `json:"final_status"`
	TotalTime      time.Duration `json:"total_time"`
	TotalRedirects int           `json:"total_redirects"`
	Error          string        `json:"error,omitempty"`
}

TraceResult holds the complete trace of an HTTP request.

func Trace

func Trace(ctx context.Context, opts TraceOptions) (*TraceResult, error)

Trace performs an HTTP request trace, following redirects and recording timing.

Jump to

Keyboard shortcuts

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