PcapFileEx.Flows.HTTP1.Exchange (pcap_file_ex v0.5.5)
View SourceAn HTTP/1.x request/response exchange.
Represents a complete or partial HTTP/1.x transaction within a flow, including request, response, timing information, and playback metadata.
Fields
flow_seq- Index within the flow's exchange list (0-based)request- The HTTP requestresponse- The HTTP response (ornilif incomplete)start_timestamp- When the request startedend_timestamp- When the response completed (ornil)response_delay_ms- Delay between request and response (for playback)complete- Whether both request and response are present
Playback Timing
response_delay_ms indicates how long to wait after receiving a request
before sending the response during playback:
- 0 if no response
- Computed as:
div(Timestamp.diff(response.timestamp, request.timestamp), 1_000_000)
Examples
# Check if exchange is complete
if exchange.complete do
IO.puts("#{exchange.request.method} #{exchange.request.path} -> #{exchange.response.status}")
end
# Access timing for playback
Process.sleep(exchange.response_delay_ms)
send_response(exchange.response)
Summary
Types
@type response() :: %{ status: non_neg_integer(), reason: String.t(), version: String.t(), headers: %{required(String.t()) => String.t()}, body: binary(), decoded_body: term() | nil, timestamp: PcapFileEx.Timestamp.t() }
@type t() :: %PcapFileEx.Flows.HTTP1.Exchange{ complete: boolean(), end_timestamp: PcapFileEx.Timestamp.t() | nil, flow_seq: non_neg_integer(), request: request(), response: response() | nil, response_delay_ms: non_neg_integer(), start_timestamp: PcapFileEx.Timestamp.t() }
Functions
Adds a response to an exchange.
Marks the exchange as complete and computes response_delay_ms.
Parameters
exchange- The exchange to updateresponse- The HTTP response map
Examples
response = %{
status: 200,
reason: "OK",
version: "1.1",
headers: %{"content-type" => "application/json"},
body: "{}",
decoded_body: %{},
timestamp: response_timestamp
}
exchange = Exchange.add_response(exchange, response)
@spec new(non_neg_integer(), request()) :: t()
Creates a new exchange with a request.
The exchange is incomplete until a response is added.
Parameters
flow_seq- Index within the flow's exchange listrequest- The HTTP request map
Examples
request = %{
method: "GET",
path: "/api/users",
version: "1.1",
headers: %{"host" => "api.example.com"},
body: "",
decoded_body: nil,
timestamp: timestamp
}
exchange = Exchange.new(0, request)