# http — Stateful HTTP/1.1 Requests, Headers & WAF Payloads (`http`)

> **FrameAssembly v3.2.2** · Protocol 46 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/http

- **Full Protocol Name:** Hypertext Transfer Protocol HTTP/1.1
- **Keyword:** `http`
- **OSI Layer & Transport:** Layer 7 · TCP 80
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 9110, RFC 9112
- **Wireshark Display Filter:** `http`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 80 -> HTTP/1.1`

## Overview

Pair a 3-way `tcp` handshake with `http get` or `http post` and FrameAssembly formats `\r\n` wire headers, computes exact `Content-Length`, and advances TCP `seq` numbers so Suricata and WAFs reassemble every byte.

Hypertext Transfer Protocol (`http`, RFC 9112) powers web traffic, REST APIs, webhooks, and reverse-proxy health checks over **TCP port `80`** (or custom ports such as `8080` via `dstport`). By default, an `http` packet builds an HTTP/1.1 request (`GET / HTTP/1.1`); adding `status <code_num>` (such as `status 200 reason "OK"`) switches the packet to an HTTP response.

FrameAssembly computes `Content-Length` automatically whenever you include `body`, supports repeatable custom `header` pairs, and keeps TCP sequence and acknowledgment numbers synchronized across the entire TCP connection.

## Minimal Quickstart (`http_quickstart.frasm`)

```frameassembly
host client  { ip 10.10.1.20 }
host web_srv { ip 10.10.1.80 }

compile {
    client -> web_srv tcp syn srcport 52100 dstport 80 wait 1ms
    client <- web_srv tcp syn ack wait 1ms
    client -> web_srv tcp ack wait 1ms
    client -> web_srv http get uri "/healthz" hosthdr "api.corp.internal" useragent "kube-probe/1.30" wait 2ms
    client <- web_srv http status 200 reason "OK" contenttype "application/json" body "{\"status\":\"healthy\"}"
}
```

### Automatic Wire Calculations

- Defaults to TCP destination port `80` with `psh ack` flags and advances TCP `seq` by the exact HTTP header + body byte count.
- Computes and inserts `Content-Length: <bytes>` automatically whenever `body` is present, formatting all header lines with standard `
` CRLF terminators.
- Remembers client/server ports on `<-` replies so `status 200` responses return from port `80` to the client’s source port automatically.

## Practical Lab Example: REST API JSON Webhook POST + WAF 403 Block Scenario (`http_api_waf_test.frasm`)

Completes a TCP handshake on port 8080, sends an authenticated JSON `POST` request with custom HTTP headers, and captures a `403 Forbidden` gateway response.

```frameassembly
host ext_client { ip 198.51.100.45 }
host waf_proxy  { ip 172.16.20.80 }

compile {
    // 1. Complete TCP 3-way handshake on port 8080 (so Suricata stream engine tracks state)
    ext_client -> waf_proxy tcp syn srcport 54320 dstport 8080 win 65535 mss 1460 wait 1ms
    ext_client <- waf_proxy tcp syn ack win 65535 mss 1460 wait 1ms
    ext_client -> waf_proxy tcp ack wait 1ms
    // 2. HTTP POST with custom headers and JSON body
    ext_client -> waf_proxy http post uri "/v1/login" hosthdr "portal.example.com" useragent "Mozilla/5.0" contenttype "application/json" header "X-Request-ID" "req-9041" header "X-Forwarded-For" "203.0.113.9" body "{\"user\":\"admin\"}" wait 3ms
    // 3. WAF blocks request with HTTP 403 Forbidden + TCP FIN
    ext_client <- waf_proxy http status 403 reason "Forbidden" contenttype "application/json" body "{\"error\":\"blocked_by_policy\"}" wait 1ms
    ext_client <- waf_proxy tcp fin ack wait 1ms
    ext_client -> waf_proxy tcp ack
}
```

```bash
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show http_api_waf_test.frasm

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly http_api_waf_test.frasm http_api_waf_test.pcap
frameassembly http_api_waf_test.frasm http_api_waf_test.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse http_api_waf_test.pcap http_api_waf_test_edited.frasm

# 4. Verify dissected protocol fields in tshark
tshark -r http_api_waf_test.pcap
```

## All `http` Keywords & Header Options

Packet line pattern: `src_host -> dst_host http [get | post | put | delete | head | options | patch | method "<text>"] [uri "<text>"] [version "<text>"] [hosthdr "<text>"] [useragent "<text>"] [contenttype "<text>"] [status <100..599>] [reason "<text>"] [header "<name>" "<value>" ...] [body "<text>"]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `get \| post \| put \| delete \| head \| options \| patch \| method "<text>"` | HTTP request method | `get` | Sets the HTTP request verb at the start of the request line. |
| `uri "<text>" \| version "<text>"` | Request path and HTTP version string | `uri "/", version "HTTP/1.1"` | Sets the request target path and protocol version (`GET /path HTTP/1.1`). |
| `hosthdr "<text>"` | Quoted hostname (e.g. "api.internal") | `Destination IP` | Writes the `Host:` HTTP header (named `hosthdr` so it never conflicts with the top-level `host` block keyword). |
| `useragent "<text>" \| contenttype "<text>"` | Quoted header values | `Omitted unless set` | Writes `User-Agent:` and `Content-Type:` headers. |
| `header "<name>" "<value>"` | Repeatable header name + value pair | `Omitted` | Appends one or more custom HTTP headers (`Authorization`, `Cookie`, `X-Forwarded-For`, etc.). |
| `status <100..599> [reason "<text>"]` | HTTP status code + optional reason phrase | `Omitted (emits request); reason "OK" when status is set` | Switches the packet from an HTTP request to an HTTP response (`HTTP/1.1 200 OK`). |
| `body "<text>"` | Quoted response or request payload | `Empty` | Appends the HTTP body after `\r\n\r\n` and calculates `Content-Length` automatically. |

## Cross-Layer Options Valid with `http`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"` or `"de:ad:be:ef"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType u16 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or 16-bit EtherType for this single packet. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255 | `Unlabeled (at most 1 mpls tag per packet)` | Inserts a 32-bit MPLS label header (`0x8847`) ahead of the Layer 3 header. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>]` | IPv4 ID, DF/MF flags, fragment offset 0..8191 | `ipid 1, flags 0, fragoffset 0` | Sets IPv4 Identification, Do-Not-Fragment (`df`), More-Fragments (`mf`), and fragment offset (ignored over IPv6). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 80` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `seq <number> \| acknum <number> \| win\|window <0..65535> \| urgent <0..65535> \| syn \| ack \| psh \| fin \| rst \| urg \| ece \| cwr` | TCP sequence/ack numbers, window size, flags & RFC 7323 options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323 options (`mss`, `wscale`, `sackperm`, `tsval`, `tsecr`). |

## Common Mistakes & Quick Fixes

### Use hosthdr (Not host) for the HTTP Host Header

- **Avoid:** `client -> web_srv http get uri "/" host "api.example.com"`
- **Valid v3.2.2 Syntax:** `client -> web_srv http get uri "/" hosthdr "api.example.com"`

Because `host` declares network endpoints at the top of a `.frasm` file, HTTP and SSDP use `hosthdr "<text>"` to set the `Host:` header.

### Include a 3-Way TCP Handshake Before HTTP for Suricata / Zeek

- **Valid v3.2.2 Syntax:** `client -> web_srv tcp syn dstport 80
client <- web_srv tcp syn ack
client -> web_srv tcp ack
client -> web_srv http get uri "/"`

Wireshark decodes standalone `http` packets immediately, but stateful IDS sensors like Suricata (`flow:established,to_server`) require the 3-packet TCP handshake first.
