feat(stdlib): add HTTP framing over TCP and close P5 C10 locally

- Add stdlib/net/http.mq.md: status/header/chunked response parsing and request
  construction in .mq.md; no host HTTP/TLS implementation.
- Add stdlib/tests/http.mq.md and an end-to-end loopback test that sends a GET
  over resource.open("tcp"), reads bytes, parses the response and returns
  status/content-type/body.
- Update ADR-0034, status/spec/README/changelog and evidence; refresh the
  bundle digest.

Gate: fmt, clippy -D warnings, 430 tests passed.
This commit is contained in:
cflmy committed 2026-11-20 23:13:06 +08:00
1 parent 0d4dc1da03
commit e981168d92
11 files changed
+486 -4

No files matched your search

+2 -1
View File
@@ -8,7 +8,8 @@ module; a mismatch is a hard error.
- `text.mq.md` — UTF-8 encoding into `Memory`
- `io.mq.md` — `写文本` / `写值` through `resource.write(stdout)`
- `demo.mq.md` — side-by-side comparison with builtin `打印`
- `data/table.mq.md` — value-returning table select/filter/sort/append/set/join/group
- `data/table.mq.md` — value-returning table select/filter/sort/append/set/join/group/GFM
- `net/http.mq.md` — HTTP/1.1 response parsing (headers/chunked) and request builder
- `tests/` — bundle self-tests
The digest is a SHA-256 over sorted `*.mq.md` relative paths, a NUL, file
+239
View File
@@ -0,0 +1,239 @@
## 切片
`(点, 起, 止)`
**结果 = ""**
**下标 = 起**
- `下标 < 止`
**结果 = 结果 + 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" + 体*
+1 -1
View File
@@ -1,5 +1,5 @@
{
"name": "marqdo-stdlib",
"version": "0.1.0",
"digest": "sha256:7a9c46fa2372017395413980f857b6863dc118c3f6c9a824abd03ddf3c59f3d4"
"digest": "sha256:832940f35fe5651eabe4ac672e12e2d8f2bf4e649cc430e455425b4f2a983121"
}
+14
View File
@@ -0,0 +1,14 @@
---
import:
http: "std:net/http"
---
## 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"**
**响应 = http.解析响应(响应文本)**
**请求 = http.构建请求("POST", "/echo", [["Host", "example.test"], ["Content-Length", "2"]], "ok")**
*[响应.状态, 响应.原因, 响应.头["Content-Type"], 响应.体, 请求]*