Files
marqdo-ext-http/tests/loopback.mq.md
cflmy a604405908
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
test: add a real HTTP-over-TCP loopback domain test
Implement marqdo-ext-http#3: the explicit @http package now owns a real
loopback domain test instead of only pure encode/parse cases.

- tests/loopback.mq.md performs two real HTTP/1.1 exchanges in one program
  through the CLI's generic resource.open("tcp")/read/write/close, building
  requests with http.构建请求字节 and parsing responses with
  http.解析响应字节; non-ASCII bodies, explicit --allow-net 127.0.0.1 and
  --allow-env HTTP_TEST_PORT only.
- scripts/loopback_server.py is a deterministic one-request-per-connection
  server that records method/path/body and returns fixed status/bodies.
- scripts/run_cases.py supports kind=loopback (server lifecycle, port env,
  grants, request-record assertions) without changing the pure case path.
- tests/cases/loopback.json asserts GET /one -> 200 第一个 and
  POST /two -> 201 第二个 plus the request records.
- Evidence: docs/evidence-2026-11-30-loopback-domain-test.md (real CLI rc.6
  candidate + Bundle 0.3.0: 2 cases PASS).

No CLI/Host/other-component change, no new Host request, no release.
2026-11-30 16:10:35 +08:00

1.9 KiB

import
import
http
@http

@exec 回环

写字节

params(资源, 字节)

内存 = memory.new(1, 1)

下标 = 0

while 下标 < 长度(字节)

内存[下标] = 字节[下标]

下标 = 下标 + 1

end

return resource.write(资源, 内存, 0, 长度(字节))

读全部

params(资源)

结果 = []

继续 = true

while 继续

内存 = memory.new(1, 1)

读 = resource.read(资源, 内存, 0, 65536)

if not 读.ok

return 读

end

数 = 读.value.count

下标 = 0

while 下标 < 数

结果 = list.append(结果, 内存[下标])

下标 = 下标 + 1

end

if 读.value.eof or 数 == 0

继续 = false

else if true

忽略 = 0

end end

end

return {ok: true, value: 结果}

交换

params(端口, 方法, 路径, 头, 体)

请求字节 = http.构建请求字节(方法, 路径, 头, http.文本字节(体))

打开 = resource.open("tcp", "127.0.0.1:" + 文本(端口), ["read", "write"])

写 = 写字节(打开, 请求字节)

if not 写.ok

return 写

end

读 = 读全部(打开)

关闭 = resource.close(打开)

if not 读.ok

return 读

end

响应 = http.解析响应字节(读.value)

if not 响应.ok

return 响应

end

正文 = http.字节文本(响应.value.body)

if not 正文.ok

return 正文

end

return {ok: true, 状态: 响应.value.status, 正文: 正文.value}

main

params()

端口读 = resource.request("env.get", ["HTTP_TEST_PORT"])

if not 端口读.ok

return [false, 0, "", false, 0, ""]

end

端口 = 整数(端口读.value)

一 = 交换(端口, "GET", "/one", "Host", "example.test", "")

二 = 交换(端口, "POST", "/two", "Host", "example.test"], ["Content-Length", "2", "ok")

return [一.ok, 一.状态, 一.正文, 二.ok, 二.状态, 二.正文]