PcapFileEx.HTTP2.Headers (pcap_file_ex v0.5.5)

View Source

HTTP/2 headers container with pseudo-header and regular header separation.

HTTP/2 defines pseudo-headers that start with : and carry request/response metadata. Regular headers follow standard HTTP semantics.

Pseudo-Headers

Request pseudo-headers:

  • :method - HTTP method (GET, POST, etc.)
  • :scheme - URI scheme (http, https)
  • :authority - Host and optional port
  • :path - Request path

Response pseudo-headers:

  • :status - Response status code

Header Types

  • Request headers: Contains :method pseudo-header
  • Response headers: Contains :status pseudo-header
  • Trailers: No pseudo-headers present (sent after body)

Summary

Functions

Get all headers (pseudo and regular) as a list.

Get the authority from request headers.

Create Headers from a list of {name, value} tuples.

Get a regular header value.

Get a regular header value as a single string.

Check if headers contain a specific pseudo-header.

Check if this is an informational response (1xx status).

Get the HTTP method from request headers.

Get the request path from request headers.

Check if these are request headers (contains :method).

Check if these are response headers (contains :status).

Get the scheme from request headers.

Get the status code from response headers.

Get the raw status string from response headers.

Get all regular headers as a list of {name, value} tuples.

Check if these are trailer headers (no pseudo-headers present).

Types

t()

@type t() :: %PcapFileEx.HTTP2.Headers{
  pseudo: %{optional(String.t()) => String.t()},
  regular: %{optional(String.t()) => String.t() | [String.t()]}
}

Functions

all_to_list(headers)

@spec all_to_list(t()) :: [{String.t(), String.t()}]

Get all headers (pseudo and regular) as a list.

Pseudo-headers come first, followed by regular headers.

authority(headers)

@spec authority(t()) :: String.t() | nil

Get the authority from request headers.

from_list(header_list)

@spec from_list([{binary(), binary()}]) :: t()

Create Headers from a list of {name, value} tuples.

Separates pseudo-headers (starting with :) from regular headers. Handles duplicate headers by converting to a list.

get(headers, name)

@spec get(t(), String.t()) :: String.t() | [String.t()] | nil

Get a regular header value.

Returns nil if header not present, or the value (String or list of Strings).

get_string(headers, name)

@spec get_string(t(), String.t()) :: String.t() | nil

Get a regular header value as a single string.

If the header has multiple values, joins them with ", ".

has_pseudo?(headers, name)

@spec has_pseudo?(t(), String.t()) :: boolean()

Check if headers contain a specific pseudo-header.

informational?(headers)

@spec informational?(t()) :: boolean()

Check if this is an informational response (1xx status).

method(headers)

@spec method(t()) :: String.t() | nil

Get the HTTP method from request headers.

path(headers)

@spec path(t()) :: String.t() | nil

Get the request path from request headers.

request?(headers)

@spec request?(t()) :: boolean()

Check if these are request headers (contains :method).

response?(headers)

@spec response?(t()) :: boolean()

Check if these are response headers (contains :status).

scheme(headers)

@spec scheme(t()) :: String.t() | nil

Get the scheme from request headers.

status(headers)

@spec status(t()) :: integer() | nil

Get the status code from response headers.

Returns the status as an integer, or nil if not present.

status_string(headers)

@spec status_string(t()) :: String.t() | nil

Get the raw status string from response headers.

to_list(headers)

@spec to_list(t()) :: [{String.t(), String.t()}]

Get all regular headers as a list of {name, value} tuples.

Multi-value headers are expanded to multiple tuples.

trailers?(headers)

@spec trailers?(t()) :: boolean()

Check if these are trailer headers (no pseudo-headers present).

Trailers are headers sent after the body data in a request or response. They cannot contain pseudo-headers.