feat: Enable returns_result for HTTP server methods
- Add returns_result = true to HttpServerBox methods (start, stop, accept) - Update all E2E tests to use .get_value() for Result handling - Prepare for gradual Result-based error handling migration This implements the first phase of ChatGPT5's Result正規化 design, starting with network-related methods as agreed. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -65,9 +65,9 @@ type_id = 20
|
||||
|
||||
[libraries."libnyash_net_plugin.so".HttpServerBox.methods]
|
||||
birth = { method_id = 0 }
|
||||
start = { method_id = 1, args = ["port"] }
|
||||
stop = { method_id = 2 }
|
||||
accept = { method_id = 3 }
|
||||
start = { method_id = 1, args = ["port"], returns_result = true }
|
||||
stop = { method_id = 2, returns_result = true }
|
||||
accept = { method_id = 3, returns_result = true }
|
||||
fini = { method_id = 4294967295 }
|
||||
|
||||
[libraries."libnyash_net_plugin.so".HttpRequestBox]
|
||||
|
||||
@ -32,7 +32,7 @@ srv.start(8080)
|
||||
cli = new HttpClientBox()
|
||||
r = cli.get("http://localhost:8080/hello")
|
||||
|
||||
req = srv.accept()
|
||||
req = srv.accept().get_value()
|
||||
resp = new HttpResponseBox()
|
||||
resp.setStatus(200)
|
||||
resp.write("OK")
|
||||
@ -62,7 +62,7 @@ srv.start(8081)
|
||||
|
||||
cli = new HttpClientBox()
|
||||
r = cli.get("http://localhost:8081/test1")
|
||||
req = srv.accept()
|
||||
req = srv.accept().get_value()
|
||||
resp = new HttpResponseBox()
|
||||
resp.write("A")
|
||||
req.respond(resp)
|
||||
@ -74,7 +74,7 @@ resp = r.get_value()
|
||||
_ = resp.readBody() # consume first response (optional)
|
||||
|
||||
r = cli.get("http://localhost:8081/test2")
|
||||
req = srv.accept()
|
||||
req = srv.accept().get_value()
|
||||
resp = new HttpResponseBox()
|
||||
resp.write("B")
|
||||
req.respond(resp)
|
||||
@ -103,7 +103,7 @@ srv = new HttpServerBox()
|
||||
srv.start(8082)
|
||||
cli = new HttpClientBox()
|
||||
r = cli.get("http://localhost:8082/first")
|
||||
req = srv.accept()
|
||||
req = srv.accept().get_value()
|
||||
resp = new HttpResponseBox()
|
||||
resp.write("X")
|
||||
req.respond(resp)
|
||||
@ -123,7 +123,7 @@ srv = new HttpServerBox()
|
||||
srv.start(8083)
|
||||
cli = new HttpClientBox()
|
||||
r = cli.get("http://localhost:8083/second")
|
||||
req = srv.accept()
|
||||
req = srv.accept().get_value()
|
||||
resp = new HttpResponseBox()
|
||||
resp.write("Y")
|
||||
req.respond(resp)
|
||||
@ -151,7 +151,7 @@ srv.start(8090)
|
||||
cli = new HttpClientBox()
|
||||
r = cli.post("http://localhost:8090/api", "DATA")
|
||||
|
||||
req = srv.accept()
|
||||
req = srv.accept().get_value()
|
||||
// check server saw body
|
||||
body = req.readBody()
|
||||
// prepare response
|
||||
@ -182,7 +182,7 @@ fn e2e_http_multiple_requests_order() {
|
||||
if !try_init_plugins() { return; }
|
||||
|
||||
let code = r#"
|
||||
local srv, cli, r1, r2, r3, q1, q2, q3
|
||||
local srv, cli, r1, r2, r3, req1, req2, req3, q1, q2, q3
|
||||
srv = new HttpServerBox()
|
||||
srv.start(8091)
|
||||
|
||||
@ -191,9 +191,12 @@ r1 = cli.get("http://localhost:8091/a")
|
||||
r2 = cli.get("http://localhost:8091/b")
|
||||
r3 = cli.get("http://localhost:8091/c")
|
||||
|
||||
q1 = srv.accept().path()
|
||||
q2 = srv.accept().path()
|
||||
q3 = srv.accept().path()
|
||||
req1 = srv.accept().get_value()
|
||||
q1 = req1.path()
|
||||
req2 = srv.accept().get_value()
|
||||
q2 = req2.path()
|
||||
req3 = srv.accept().get_value()
|
||||
q3 = req3.path()
|
||||
|
||||
q1 + "," + q2 + "," + q3
|
||||
"#;
|
||||
|
||||
@ -36,8 +36,8 @@ r1 = c.get("http://localhost:8101/a")
|
||||
r2 = c.get("http://localhost:8102/b")
|
||||
|
||||
// accept once per pending request and keep handles
|
||||
req1 = s1.accept()
|
||||
req2 = s2.accept()
|
||||
req1 = s1.accept().get_value()
|
||||
req2 = s2.accept().get_value()
|
||||
p1 = req1.path()
|
||||
p2 = req2.path()
|
||||
|
||||
@ -78,7 +78,7 @@ s.start(8103)
|
||||
c = new HttpClientBox()
|
||||
r = c.post("http://localhost:8103/long", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
||||
|
||||
q = s.accept()
|
||||
q = s.accept().get_value()
|
||||
body = q.readBody()
|
||||
resp = new HttpResponseBox()
|
||||
resp.setStatus(202)
|
||||
|
||||
Reference in New Issue
Block a user