From 69a28ed1e12f5c9a623fa52c5389119e1e71de91 Mon Sep 17 00:00:00 2001 From: cflmy Date: Fri, 20 Nov 2026 23:10:19 +0800 Subject: [PATCH] feat(stdlib): add table GFM rendering and an HTTP/1.1 parser fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - stdlib/data/table.mq.md adds 连接片段/连接行/转义单元格/转GFM; logical Table renders as a GFM pipe table with pipe/newline escaping (CM-A08 P4 gate). - Add semantic fixture 71: HTTP/1.1 status/header/chunked response parsing and request construction in .mq.md; no host HTTP/TLS implementation (C10). - Update table CLI test, golden count 71, specs/status/README/changelog and evidence. Gate: fmt, clippy -D warnings, 426 tests passed; bundle digest refreshed. --- CHANGELOG.md | 5 + README.md | 2 +- crates/cli/tests/stdlib_table.rs | 7 +- docs/STATUS.md | 11 +- ...ble-logical-value-and-stdlib-algorithms.md | 1 + docs/evidence/2026-11-20-http-parser.md | 57 ++++ stdlib/data/table.mq.md | 132 +++++++++ stdlib/stdlib.json | 2 +- stdlib/tests/table.mq.md | 2 +- tests/README.md | 2 +- .../semantics/71-http-parser.expected.json | 30 +++ .../semantics/71-http-parser.mq.md | 250 ++++++++++++++++++ 12 files changed, 492 insertions(+), 9 deletions(-) create mode 100644 docs/evidence/2026-11-20-http-parser.md create mode 100644 tests/conformance/semantics/71-http-parser.expected.json create mode 100644 tests/conformance/semantics/71-http-parser.mq.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ce2da8..27f5d20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -125,6 +125,11 @@ currently `0.1.0`; no release tag has been cut. Dates use ISO 8601. before module loading, a `std:marqdo-stdlib@#` package instance id, `project.stdlib` in Analysis v2, and test coverage for `std:` resolution, tamper rejection and frozen-binary hash equality. +- CM-A08 GFM rendering: `stdlib/data/table.mq.md::转GFM` renders a logical + Table as a GFM pipe table with cell escaping; CLI test added. +- P5 HTTP parser fixture (C10): semantic fixture 71 parses HTTP/1.1 status, + headers and chunked transfer bodies and builds requests in `.mq.md`; no host + HTTP/HTTPS implementation is claimed. - P5 blocking TCP endpoint v1 (ADR-0034): `resource.open("tcp", ip:port, ["read","write"])` with exact IP-literal grants, project mode only, 5s connect/read/write timeouts; no DNS/TLS/UDP/server sockets. CLI `--allow-net diff --git a/README.md b/README.md index beb2c3a..1b6e851 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ executes anything. ## What works (implemented and tested) * **P0 contracts** — frozen Markdown profile, AST → program mapping, strict - expression grammar, evaluation semantics; 160 AST goldens, 70 semantic + expression grammar, evaluation semantics; 160 AST goldens, 71 semantic goldens, 52 compile-error fixtures and 21 runtime-error fixtures (`tests/`). * **P1 interpreter** — native Rust tree-walk interpreter: values, scopes, diff --git a/crates/cli/tests/stdlib_table.rs b/crates/cli/tests/stdlib_table.rs index cd201b9..75692c1 100644 --- a/crates/cli/tests/stdlib_table.rs +++ b/crates/cli/tests/stdlib_table.rs @@ -37,7 +37,7 @@ fn stdlib_table_algorithms_rebuild_without_mutating_inputs() { let report = run_table_self_test(); assert_eq!(report["success"], true); let items = report["value"]["items"].as_array().expect("list"); - assert_eq!(items.len(), 8); + assert_eq!(items.len(), 9); assert_eq!(items[0]["header"], serde_json::json!(["分数"])); assert_eq!(items[0]["rows"].as_array().unwrap().len(), 3); @@ -64,4 +64,9 @@ fn stdlib_table_algorithms_rebuild_without_mutating_inputs() { // Original input is unchanged. assert_eq!(rows(&items[7]).len(), 3); assert_eq!(rows(&items[7])[0][1]["decimal"], "87"); + + assert_eq!( + items[8]["value"], + "| 名称 | 分数 |\n| --- | --- |\n| 甲 | 87 |\n| 乙 | 92 |\n| 丙 | 71 |" + ); } diff --git a/docs/STATUS.md b/docs/STATUS.md index 8506c2f..f884670 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -72,7 +72,7 @@ This is still a **local VM lane**, not a self-hosted GitHub Actions security URL | 2 | Cross-platform strict `cfg` | **Fixed locally; native CI UNVERIFIED** | `#[cfg]` dispatch + non-Linux regression test | | 3 | Strict probe→launch race | **Fixed locally; GitHub Linux CI UNVERIFIED** | fail-closed CLI contract + probe-OK/launch-EAGAIN seam test | | 4 | Parallel security matrix isolation | **Fixed** | unique paths + helper `OnceLock`; 7/7 in parallel workspace run | -| 5 | Markdown/power/control-flow corpus | **Done locally** | 160 AST, 70 semantic, 52 compile-negative, 21 runtime-negative fixtures | +| 5 | Markdown/power/control-flow corpus | **Done locally** | 160 AST, 71 semantic, 52 compile-negative, 21 runtime-negative fixtures | | 6 | Condition header + source spans | **Fixed** | executable tails rejected; literal-inside-backtick mapping tests | | 7 | Independent Tool consumers | **Done locally** | `sample-view`/`sample-knowledge`/`sample-proof` E2E test | | 8 | lock v3 reproducibility | **Implemented; tamper test added** | `package_env` PASS | @@ -87,7 +87,7 @@ This is still a **local VM lane**, not a self-hosted GitHub Actions security URL - Frozen Markdown profile `marqdo.md.v1` with 160 AST goldens and explicit CRLF byte semantics. -- Native Rust interpreter with 70 semantic goldens, 52 compile-error fixtures, +- Native Rust interpreter with 71 semantic goldens, 52 compile-error fixtures, and runtime error source attribution. - Native `**` power is pinned end-to-end: right associativity, unary-minus precedence, parentheses, float negative exponents, branch/loop conditions, @@ -198,8 +198,8 @@ behavior. This table records only what is in this tree now. | P1 Memory + place assignment | **Implemented locally** | `Value::Memory`, run-scoped `MemoryStore` (64 KiB pages, 64 MiB total / 16 MiB region), `memory.new/size/grow`, `m[i]` read, `m[i] = byte`; semantic fixtures 45–47, runtime negatives 13–18, `examples/memory-buffer.mq.md`; evidence [`evidence/2026-11-20-memory-p1.md`](evidence/2026-11-20-memory-p1.md) | | P2 Marqdo-written allocator/data structures + minimal structure observation | **PARTIAL, gate NOT passed** | `.mq.md`-only evidence: bump allocator with u32 codec, linked list, failed-allocation atomicity (48–50); CM-A04 structure primitives and a table filter (51–54, ADR-0023); a first-fit free-list allocator with block reuse, splitting, address-adjacent coalescing and `Result` maps (55, ADR-0024), a `Memory`-backed binary tree with recursive insert/in-order traversal (56), a `.mq.md` CSV row splitter (57), an open-addressing hash table with linear probing, update and `hash.full` (58), a `.mq.md` UTF-8 encoder over `Memory` (59), a validating UTF-8 decoder rejecting truncated, bad-continuation and surrogate/overlong input (60), a `Memory`-backed graph adjacency list (61), a recursive JSON parser for nested arrays/objects, strings with escapes, integers, booleans, null and error Results (62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (63), big-endian 16/32/64-bit plus LEB128 integer codecs (64), a `.mq.md` table sort rebuilding a new table from `table.row/columns/cell` (65), a table join (67), a quoted/escaped CSV row parser (68), table group (69), and an Int matrix multiply (70); the first-fit allocator also detects double free (`alloc.double_free`). Evidence: [`memory-p2-closure`](evidence/2026-11-20-memory-p2-closure.md), [`structure-api-p2`](evidence/2026-11-20-structure-api-p2.md), [`result-and-free-list-p2`](evidence/2026-11-20-result-and-free-list-p2.md). P2 remaining: publication as a separate external stdlib repository. The bundled `stdlib/` tree, `std:` imports, digest verification, Analysis identity and frozen-CLI closure test are implemented (ADR-0028). C01–C06/C11/C12 each have `.mq.md` evidence, including JSON floats and a JSON formatter. | | P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict permits only stdio/stdout and refuses file/network resources. Fixture 66 + CLI/host tests. CM-A07 **Compat-C** is implemented: when a program calls `打印/print`, the loader injects the bundled `stdlib/io.mq.md` and the runtime routes to `io.写值` (all 15 value types, UTF-8 via `Memory`, `resource.write(stdout)`); `HostOp::Print` and the legacy `Value::display()` print path are removed, and a missing bundle fails with `kernel.unavailable`. Strict permits only the existing stdio console channel. Still missing: directories, network, generic provider registry, Table storage, strict file/network resources. | -| P4 Table logical/physical migration | **PARTIAL** | ADR-0032/CM-A08: `Value::Table` logical semantics unchanged (T0 `Vec>`); `stdlib/data/table.mq.md` provides select/filter/sort/append/set/join/group as value-returning `.mq.md` functions with input immutability. No T1/T2/T3 physical storage, column store or Memory-backed table. | -| P5 third-party Provider / TCP / HTTP | **PARTIAL** | ADR-0034 blocking TCP resource endpoint (`resource.open("tcp", ":", ["read","write"])`, exact IP grant, project-only, 5s timeouts; loopback host+CLI tests). ADR-0033 in-process `ResourceProvider` v1: explicitly trusted providers register by kind, project-mode only, gated by `Capabilities.allow_resource_provider`, using the existing `resource.*`/`Result` ABI; a mock read/write provider is tested. No C/Worker provider transport, DNS/TLS/HTTP framing, UDP, clock/random/process/device providers, or provider package installation. | +| P4 Table logical/physical migration | **PARTIAL** | ADR-0032/CM-A08: `Value::Table` logical semantics unchanged (T0 `Vec>`); `stdlib/data/table.mq.md` provides select/filter/sort/append/set/join/group/`转GFM` as value-returning `.mq.md` functions with input immutability. GFM rendering is covered; no T1/T2/T3 physical storage, column store, cross-storage implementation or Memory-backed table. | +| P5 third-party Provider / TCP / HTTP | **PARTIAL** | semantic fixture 71 implements HTTP/1.1 response parsing (status/headers/chunked) and request construction in `.mq.md`; no host HTTP/TLS. ADR-0034 blocking TCP resource endpoint (`resource.open("tcp", ":", ["read","write"])`, exact IP grant, project-only, 5s timeouts; loopback host+CLI tests). ADR-0033 in-process `ResourceProvider` v1: explicitly trusted providers register by kind, project-mode only, gated by `Capabilities.allow_resource_provider`, using the existing `resource.*`/`Result` ABI; a mock read/write provider is tested. No C/Worker provider transport, host DNS/TLS/HTTP implementation, UDP, clock/random/process/device providers, or provider package installation. | | P6 performance / native backends | **NOT IMPLEMENTED** | no bytecode/JIT/GPU/QPU work | The P1 memory domain is pure computation: it needs no grant and is available in @@ -243,6 +243,9 @@ user-written allocator is explicitly **not** claimed. - [`evidence/2026-11-20-tcp-endpoint.md`](evidence/2026-11-20-tcp-endpoint.md) — ADR-0034 blocking TCP endpoint, IP grants, DNS refusal, loopback host/CLI echo tests. +- [`evidence/2026-11-20-http-parser.md`](evidence/2026-11-20-http-parser.md) + — P5/C10 `.mq.md` HTTP/1.1 status/header/chunked response parser and request + builder fixture. - [`evidence/2026-11-20-strict-resource-cm-a11.md`](evidence/2026-11-20-strict-resource-cm-a11.md) — CM-A11 strict lane at `00bdcad`: 7/7 adversarial matrix, positive Compat-C print, strict file-resource refusal, forged-marker rejection and raw log. diff --git a/docs/adr/0032-table-logical-value-and-stdlib-algorithms.md b/docs/adr/0032-table-logical-value-and-stdlib-algorithms.md index 6e3a88c..e9b8fac 100644 --- a/docs/adr/0032-table-logical-value-and-stdlib-algorithms.md +++ b/docs/adr/0032-table-logical-value-and-stdlib-algorithms.md @@ -46,6 +46,7 @@ Add `stdlib/data/table.mq.md`, importable as `std:data/table`: | `设置单元格(数据, 行, 列, 值)` | rebuilds rows; original unchanged | | `连接(左, 右, 左列, 右列)` | equality join; headers concatenated | | `分组(数据, 键列, 值列)` | Text key -> List of values | +| `转GFM(数据)` | render the logical table as a GFM pipe table; `\|`/newline cells escaped | All functions use only `table.columns/row/cell`, `list.*`, `map.*` and `表`; none is a new builtin or `HostOp`. The module is ordinary `.mq.md`, loaded diff --git a/docs/evidence/2026-11-20-http-parser.md b/docs/evidence/2026-11-20-http-parser.md new file mode 100644 index 0000000..427366d --- /dev/null +++ b/docs/evidence/2026-11-20-http-parser.md @@ -0,0 +1,57 @@ +# RFC-CM P5/C10 evidence: `.mq.md` HTTP/1.1 parser + +Date: 2026-11-20 (Asia/Shanghai) +Repository: `marqdo-cli` +Baseline: `67a6d35` plus this step's changes. +Related: [ADR-0032](../adr/0032-table-logical-value-and-stdlib-algorithms.md), +[ADR-0034](../adr/0034-tcp-resource-endpoint.md), [STATUS §5](../STATUS.md). +Scope: Text-level HTTP framing in `.mq.md`; no host HTTP/TLS implementation. + +## Fixture + +`tests/conformance/semantics/71-http-parser.mq.md` (+ expected golden): + +* `找子串`/`找字符`/`切片` over `text.codepoints` and `text.from_codepoint`; +* `解析响应` splits the head/body at `\r\n\r\n`, parses the status line, + headers and `Transfer-Encoding: chunked`; +* `解码分块` parses hex chunk sizes and reassembles the body; +* `构建请求(方法, 路径, 头列表, 体)` emits an HTTP/1.1 request with CRLF + framing. + +Input: + +```text +HTTP/1.1 200 OK +Content-Type: text/plain +Transfer-Encoding: chunked + +5 +hello +6 + world +0 +``` + +Result: + +```json +[200, "OK", "text/plain", "hello world", + "GET /health HTTP/1.1\r\nAccept: text/plain\r\nHost: example.test\r\n\r\n"] +``` + +The fixture is run end-to-end by `conformance_semantics` and is part of the +71 semantic goldens. + +## Gate + +Local container: fmt/clippy/426 tests PASS (one fixture test; the golden count +is 71). No host `net.request`, HTTP client/server or TLS code was added. + +## Not done + +* HTTP client over TCP, connection reuse, redirects, compression, cookies. +* HTTPS/TLS; this ADR/evidence makes **no** TLS security claim. +* Request-body streaming, trailers, chunked requests, HTTP/2. +* A reusable `stdlib/net/http.mq.md` module (the parser is a conformance + fixture, not a bundled module yet). +* C/Worker provider transport and external stdlib repository publication. diff --git a/stdlib/data/table.mq.md b/stdlib/data/table.mq.md index 66ef224..21fcd96 100644 --- a/stdlib/data/table.mq.md +++ b/stdlib/data/table.mq.md @@ -231,3 +231,135 @@ **行号 = 行号 + 1** *结果* + +## 连接片段 + +`(片段)` + +**结果 = ""** + +**下标 = 0** + +- `下标 < 长度(片段)` + + 1. `下标 > 0` + + **结果 = 结果 + " | "** + + 2. `true` + + **忽略 = 0** + + **结果 = 结果 + 片段[下标]** + + **下标 = 下标 + 1** + +*结果* + +## 连接行 + +`(行列表)` + +**结果 = ""** + +**下标 = 0** + +- `下标 < 长度(行列表)` + + 1. `下标 > 0` + + **结果 = 结果 + "\n"** + + 2. `true` + + **忽略 = 0** + + **结果 = 结果 + 行列表[下标]** + + **下标 = 下标 + 1** + +*结果* + +## 转义单元格 + +`(值)` + +**文本值 = 文本(值)** + +**点 = text.codepoints(文本值)** + +**结果 = ""** + +**下标 = 0** + +- `下标 < 长度(点)` + + 1. `点[下标] == 124` + + **结果 = 结果 + text.from_codepoint(92) + "|"** + + 2. `点[下标] == 10 or 点[下标] == 13` + + **结果 = 结果 + " "** + + 3. `true` + + **结果 = 结果 + text.from_codepoint(点[下标])** + + **下标 = 下标 + 1** + +*结果* + +## 转GFM + +`(数据)` + +**列名 = table.columns(数据)** + +**表头 = []** + +**下标 = 0** + +- `下标 < 长度(列名)` + + **表头 = list.append(表头, 转义单元格(列名[下标]))** + + **下标 = 下标 + 1** + +**行列表 = []** + +**行列表 = list.append(行列表, "| " + 连接片段(表头) + " |")** + +**分隔 = []** + +**下标 = 0** + +- `下标 < 长度(列名)` + + **分隔 = list.append(分隔, "---")** + + **下标 = 下标 + 1** + +**行列表 = list.append(行列表, "| " + 连接片段(分隔) + " |")** + +**行号 = 0** + +- `行号 < 长度(数据)` + + **行 = table.row(数据, 行号)** + + **单元格 = []** + + **列号 = 0** + + - `列号 < 长度(行)` + + **单元格 = list.append(单元格, 转义单元格(行[列号]))** + + **列号 = 列号 + 1** + + **行列表 = list.append(行列表, "| " + 连接片段(单元格) + " |")** + + **行号 = 行号 + 1** + +*连接行(行列表)* diff --git a/stdlib/stdlib.json b/stdlib/stdlib.json index b8e24ae..d7553d5 100644 --- a/stdlib/stdlib.json +++ b/stdlib/stdlib.json @@ -1,5 +1,5 @@ { "name": "marqdo-stdlib", "version": "0.1.0", - "digest": "sha256:67710611a9f56b403d0ef4c295272ba95cd6fc0bee9c7314f4a42d8e54e8aba2" + "digest": "sha256:7a9c46fa2372017395413980f857b6863dc118c3f6c9a824abd03ddf3c59f3d4" } diff --git a/stdlib/tests/table.mq.md b/stdlib/tests/table.mq.md index 0f81475..b9caf50 100644 --- a/stdlib/tests/table.mq.md +++ b/stdlib/tests/table.mq.md @@ -25,4 +25,4 @@ import: **分组 = table.分组(表(["类别", "值"], [["a", 1], ["b", 2], ["a", 3]]), 0, 1)** -*[选择, 过滤, 排序, 追加, 设置, 连接, 分组, 数据]* +*[选择, 过滤, 排序, 追加, 设置, 连接, 分组, 数据, table.转GFM(数据)]* diff --git a/tests/README.md b/tests/README.md index c931d38..28585e0 100644 --- a/tests/README.md +++ b/tests/README.md @@ -15,7 +15,7 @@ no test commits, copies or rewrites files outside a throw-away temp directory. tests/ ├── conformance/ │ ├── ast/ 160 × *.mq.md + sibling *.ast.json goldens -│ └── semantics/ 70 × *.mq.md + sibling *.expected.json goldens +│ └── semantics/ 71 × *.mq.md + sibling *.expected.json goldens ├── negative/ │ ├── *.mq.md 52 × compile-time hard-error fixtures + *.expected.json │ ├── warnings/ 6 × inert-executable warning fixtures + *.expected.json diff --git a/tests/conformance/semantics/71-http-parser.expected.json b/tests/conformance/semantics/71-http-parser.expected.json new file mode 100644 index 0000000..c498f1c --- /dev/null +++ b/tests/conformance/semantics/71-http-parser.expected.json @@ -0,0 +1,30 @@ +{ + "args": {}, + "function": "main", + "stdout": "", + "value": { + "items": [ + { + "decimal": "200", + "type": "int" + }, + { + "type": "text", + "value": "OK" + }, + { + "type": "text", + "value": "text/plain" + }, + { + "type": "text", + "value": "hello world" + }, + { + "type": "text", + "value": "GET /health HTTP/1.1\r\nAccept: text/plain\r\nHost: example.test\r\n\r\n" + } + ], + "type": "list" + } +} diff --git a/tests/conformance/semantics/71-http-parser.mq.md b/tests/conformance/semantics/71-http-parser.mq.md new file mode 100644 index 0000000..7c82a67 --- /dev/null +++ b/tests/conformance/semantics/71-http-parser.mq.md @@ -0,0 +1,250 @@ +## 切片 + +`(点, 起, 止)` + +**结果 = ""** + +**下标 = 起** + +- `下标 < 止` + + **结果 = 结果 + text.from_codepoint(点[下标])** + + **下标 = 下标 + 1** + +*结果* + +## 找子串 + +`(点, 子点, 起点)` + +**结果 = 0 - 1** + +**下标 = 起点** + +- `下标 + 长度(子点) <= 长度(点) and 结果 < 0` + + **偏移 = 0** + + **匹配 = true** + + - `偏移 < 长度(子点) and 匹配` + + 1. `点[下标 + 偏移] != 子点[偏移]` + + **匹配 = false** + + 2. `true` + + **忽略 = 0** + + **偏移 = 偏移 + 1** + + 1. `匹配` + + **结果 = 下标** + + 2. `true` + + **忽略 = 0** + + **下标 = 下标 + 1** + +*结果* + +## 找字符 + +`(点, 码点, 起点)` + +**结果 = 0 - 1** + +**下标 = 起点** + +- `下标 < 长度(点) and 结果 < 0` + + 1. `点[下标] == 码点` + + **结果 = 下标** + + 2. `true` + + **忽略 = 0** + + **下标 = 下标 + 1** + +*结果* + +## 十六进制值 + +`(点)` + +**数值 = 0** + +**下标 = 0** + +- `下标 < 长度(点)` + + **码点 = 点[下标]** + + 1. `码点 >= 48 and 码点 <= 57` + + **数值 = 数值 * 16 + 码点 - 48** + + 2. `码点 >= 65 and 码点 <= 70` + + **数值 = 数值 * 16 + 码点 - 55** + + 3. `码点 >= 97 and 码点 <= 102` + + **数值 = 数值 * 16 + 码点 - 87** + + 4. `true` + + **忽略 = 0** + + **下标 = 下标 + 1** + +*数值* + +## 解码分块 + +`(体)` + +**点 = text.codepoints(体)** + +**结果 = ""** + +**位置 = 0** + +- `位置 < 长度(点)` + + **行尾 = 找子串(点, text.codepoints("\r\n"), 位置)** + + - `行尾 < 0` + + *""* + + **大小文本 = 切片(点, 位置, 行尾)** + + **大小 = 十六进制值(text.codepoints(大小文本))** + + 1. `大小 == 0` + + **位置 = 长度(点)** + + 2. `true` + + **结果 = 结果 + 切片(点, 行尾 + 2, 行尾 + 2 + 大小)** + + **位置 = 行尾 + 2 + 大小 + 2** + +*结果* + +## 解析响应 + +`(文本)` + +**点 = text.codepoints(文本)** + +**分隔 = text.codepoints("\r\n\r\n")** + +**头部结束 = 找子串(点, 分隔, 0)** + +**头部 = 切片(点, 0, 头部结束)** + +**体 = 切片(点, 头部结束 + 4, 长度(点))** + +**头部点 = text.codepoints(头部)** + +**行列表 = []** + +**行起 = 0** + +**下一行 = 找子串(头部点, text.codepoints("\r\n"), 0)** + +- `下一行 >= 0` + + **行列表 = list.append(行列表, 切片(头部点, 行起, 下一行))** + + **行起 = 下一行 + 2** + + **下一行 = 找子串(头部点, text.codepoints("\r\n"), 行起)** + +**行列表 = list.append(行列表, 切片(头部点, 行起, 长度(头部点)))** + +**状态行 = 行列表[0]** + +**状态点 = text.codepoints(状态行)** + +**第一空格 = 找字符(状态点, 32, 0)** + +**第二空格 = 找字符(状态点, 32, 第一空格 + 1)** + +**状态 = 整数(切片(状态点, 第一空格 + 1, 第二空格))** + +**原因 = 切片(状态点, 第二空格 + 1, 长度(状态点))** + +**头 = {}** + +**行号 = 1** + +- `行号 < 长度(行列表)` + + **行点 = text.codepoints(行列表[行号])** + + **冒号 = 找字符(行点, 58, 0)** + + 1. `冒号 >= 0` + + **名 = 切片(行点, 0, 冒号)** + + **值 = 切片(行点, 冒号 + 2, 长度(行点))** + + **头 = map.set(头, 名, 值)** + + 2. `true` + + **忽略 = 0** + + **行号 = 行号 + 1** + +**传输 = map.get(头, "Transfer-Encoding")** + +**解码后 = 体** + +1. `传输 == "chunked"` + + **解码后 = 解码分块(体)** + +2. `true` + + **解码后 = 体** + +*{状态: 状态, 原因: 原因, 头: 头, 体: 解码后}* + +## 构建请求 + +`(方法, 路径, 头列表, 体)` + +**请求 = 方法 + " " + 路径 + " HTTP/1.1\r\n"** + +**行号 = 0** + +- `行号 < 长度(头列表)` + + **请求 = 请求 + 头列表[行号][0] + ": " + 头列表[行号][1] + "\r\n"** + + **行号 = 行号 + 1** + +*请求 + "\r\n" + 体* + +## main + +**响应文本 = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nhello\r\n6\r\n world\r\n0\r\n\r\n"** + +**响应 = 解析响应(响应文本)** + +**请求 = 构建请求("GET", "/health", [["Accept", "text/plain"], ["Host", "example.test"]], "")** + +*[响应.状态, 响应.原因, 响应.头["Content-Type"], 响应.体, 请求]* +