- Add e2e_vm_http_status_404/500 tests to verify HTTP status handling - ResultBox properly returns Ok(Response) for HTTP errors, Err for connection failures - Create dynamic-plugin-flow.md documenting MIR→VM→Registry→Plugin flow - Add vm-stats test files for HTTP 404/500 status codes - Update net-plugin.md with HTTP error handling clarification - Create E2E_TESTS.md documenting all E2E test behaviors - Add mir-26-instruction-diet.md for MIR optimization plans - Add vm-stats-cookbook.md for VM statistics usage guide - Update MIR verifier to properly track self-assignment patterns 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
3.0 KiB
3.0 KiB
Net Plugin (HTTP over TCP PoC)
最終更新: 2025-08-22
概要
nyash-net-pluginは Socket/HTTP をプラグインとして提供します。- HTTP は最小限の HTTP/1.1 実装(GET/POST、ヘッダ、Content-Length)を実ソケットで処理します。
提供Box
SocketServerBox,SocketClientBox,SocketConnBoxHttpServerBox,HttpRequestBox,HttpResponseBox,HttpClientBox
nyash.toml 定義例(抜粋)はリポジトリ直下の nyash.toml を参照。
動作仕様(HTTP)
- Server
start(port): TCP待受を開始accept(): 接続受理+リクエスト簡易パース(path/body)→HttpRequestBoxを返すHttpRequestBox.respond(resp):respの status/header/body を HTTP/1.1 として送出(Connection: close)
- Client
get(url),post(url, body): host:port に接続し、HTTP/1.1 リクエストを送出HttpResponseBoxは遅延受信。readBody()/getStatus()/getHeader()呼び出し時に受信・パース
制限:
- Chunked/Keep-Alive/HTTP/2は非対応(PoC)。Content-Length のみ対応。
エラーモデル(PoC)
- BID-FFI の負値(例:
-5PluginError)は Nyash 側で例外(RuntimeFailure)として扱われます。 - タイムアウト系(Socket の
acceptTimeout/recvTimeout)はエラーではなく、以下の値を返します:acceptTimeout(ms): タイムアウト時はvoidrecvTimeout(ms): タイムアウト時は 空bytes(長さ0の文字列)
HTTPエラーハンドリング(重要)
- 接続失敗(unreachable):
Result.Err(ErrorBox)を返す- 例: ポート8099に接続できない →
Err("connect failed for 127.0.0.1:8099/...")
- 例: ポート8099に接続できない →
- HTTPステータスエラー(404/500等):
Result.Ok(HttpResponseBox)を返す- 例: 404 Not Found →
Ok(response)でresponse.getStatus()が 404 - トランスポート層は成功、アプリケーション層のエラーとして扱う
- 例: 404 Not Found →
将来の整合:
ResultBoxでの返却に対応する設計(Ok(value)/Err(ErrorBox))を検討中。nyash.tomlのメソッド宣言に戻り値型(Result)を記載し、ランタイムで自動ラップする案。
並列E2E運用の注意
- 各テストで異なるポートを使用(例: 8080/8081/8090/8091...)
- サーバの
stop()と再起動時はポート開放の遅延に注意(短い待機を挟むと安定) - ログを有効化して競合や順序の問題を診断可能
ログ出力
環境変数で簡易ログを有効化できます。
export NYASH_NET_LOG=1
export NYASH_NET_LOG_FILE=net_plugin.log
stderr とファイルの両方に出力されます。
例
local srv, cli, r, req, resp
srv = new HttpServerBox()
srv.start(8080)
cli = new HttpClientBox()
r = cli.get("http://localhost:8080/hello")
req = srv.accept()
resp = new HttpResponseBox()
resp.setStatus(200)
resp.setHeader("X-Test", "V")
resp.write("OK")
req.respond(resp)
// client side
print(r.getStatus())
print(r.getHeader("X-Test"))
print(r.readBody())