Skip to content

http.parse

HTTP/1.1 请求行/状态行/头部解析(P4-A 协议半层) 形态(发射面事实,divergences 服务器面 (a)/(f)/(g) 已证形态): ① 零 use 纯模块:不 import std.net(加载器菱形 use 误报 E5020,tls.ct ⑥ 同款规避);不 import std.strconv(RFC 语法严格档与通用解析口径不同, CL/ chunk-size 解析内建:1DIGIT / 1HEXDIG + 溢出界门)。纯 Ctron ⇒ 解释器(ctron-cc run)可直接承载测试(tests/http/run.sh 主口径)。 ② 缓冲 = &I64[] 字节道(每字节一条 I64 lane,net.ct 头注④同款);一切 提取物 = 切片四元组(start,len)零拷贝指向缓冲,不分配 Str。索引全程 I64(道下标);Str 侧 byte_at 需 I32 处经 .as[I32]() 显式变宽收窄。 ③ 错误面 = rc 槽(net.ct ③ 同款,Result[struct,_] Ok 成员访问不可发射): rc = 1 完整头部(out 各槽有效;head_end = 头块结束哨兵,体从该位起) rc = 0 需要更多字节(增量可重入:换更大缓冲/原缓冲追加后重调, 解析为纯重扫,无隐藏状态 —— 游标即 head_end,完成前恒 0) rc = -1 协议/上限违规(err 槽 = 下列码;框架层后续映射 HTTP 状态: 400/414/431/413/505 —— 码位即映射表,P4 不做状态行发射) ④ RFC 9110/9112 严格子集(走私加固姿态,从严即默认): - 方法/头名 = token(tchar 校验);请求目标 VCHAR 非空; - 版本仅 "HTTP/1.1"|"HTTP/1.0"(大小写敏感,恰 8 字节,拒 HTTP/1.10); - obs-fold(续行以 SP/HTAB 起头)拒绝(E_FOLD,RFC 9112 §5.2 裁量从窄); - 行终止仅 CRLF(裸 LF 拒 —— 走私加固;RFC 9112 §2.2 宽容档不采); - Transfer-Encoding 与 Content-Length 并存 → E_SMUGGLE(RFC 9112 §6.1 裁量"拒";两值相等亦拒 —— 简单姿态优先); - Content-Length 重复(即使值相同)→ E_CL(逗号并值含非数字自然被拒); - TE 存在且末编码非 chunked → E_TE(框架映射 501); - 头名与 ':' 之间有 SP/HTAB → E_HDR(RFC 9110 §5.1 必须 400); ⑤ 上限参数化(HttpLimits,五槽);P4 缺省 = max_line 8192 / max_headers 100 / max_header 8192 / max_head 65536 / max_body 1048576。超限各给 独立 err 码(414=行超限 / 431=头数·头长·头总超限 / 413=体超限)。 ⑥ 无闭包、无 Drop 局部、无 trait 方法、无方法调用 —— 全自由函数 + 值 struct 进出((f)/(g) 已证形态;while 体仅标量与无 Drop 结构局部)。 IO 粘合(读道/写道经 net 门面)归框架波次;本文件为纯编解码半层(§11.7 分层纪律:协议半层禁止内嵌业务;Capability 显形由消费方 net: StdNet 首参 贯穿,如 tls.ct)。

pub fn

Signature Returns Description
http_limits_default() HttpLimits —
http_err_line() I64 err 码(err 槽;括注 = 框架层映射目标,P4 只出码)
http_err_line_long() I64 —
http_err_version() I64 —
http_err_token() I64 —
http_err_target() I64 —
http_err_hdr() I64 —
http_err_fold() I64 —
http_err_hdr_long() I64 —
http_err_hdr_many() I64 —
http_err_head_long() I64 —
http_err_smuggle() I64 —
http_err_cl() I64 —
http_err_te() I64 —
http_err_bodycap() I64 —
http_parse_head(buf: &[I64], n: I64, lim: HttpLimits) HttpHead 解析头部块(buf[0..n) 已收字节;增量口径:rc=0 时追加字节后整体重调 ——
纯重扫无隐藏状态,可任意次重入直至 rc != 0)。响应/请求自适应:缓冲以
"HTTP/" 起头按状态行解析,否则按请求行。
http_header_at(buf: &[I64], h: HttpHead, idx: I64) HttpSlice 第 idx 条头(idx 自 0;rc = -1 越界)。name/value 切片零拷贝,value 已去 OWS。
http_header_find(buf: &[I64], h: HttpHead, name: Str) I64 首条名匹配头(大小写不敏感)→ 下标;无 → -1
http_header_value(buf: &[I64], h: HttpHead, name: Str) HttpSlice 首条名匹配头的 value 切片(rc = -1 未找到)
http_keep_alive(buf: &[I64], h: HttpHead) I64 keep-alive 判:1.1 缺省开,1.0 缺省关;Connection 头 token 表显式翻面。
http_is_expect_100(buf: &[I64], h: HttpHead) I64 Expect: 100-continue 检出(大小写不敏感;他值按 RFC 必须忽略 → 0)
http_rc(h: HttpHead) I64 —
http_err_of(h: HttpHead) I64 —
http_is_resp(h: HttpHead) I64 —
http_ver(h: HttpHead) I64 —
http_status_of(h: HttpHead) I64 —
http_head_end(h: HttpHead) I64 —
http_nheaders(h: HttpHead) I64 —
http_body_kind(h: HttpHead) I64 —
http_clen(h: HttpHead) I64 —
http_method_start(h: HttpHead) I64 —
http_method_len(h: HttpHead) I64 —
http_target_start(h: HttpHead) I64 —
http_target_len(h: HttpHead) I64 —
sl_rc(s: HttpSlice) I64 —
sl_ns(s: HttpSlice) I64 —
sl_nl(s: HttpSlice) I64 —
sl_vs(s: HttpSlice) I64 —
sl_vl(s: HttpSlice) I64 —