// app/echo_server.prg — 1a.2b end-to-end test. // // Starts the built-in HTTP server on :8089 with OnRequest as the // dispatcher. The handler echoes the request back as JSON so we can // curl it and verify request parsing + response writing both work. FUNCTION Main() LOCAL cErr := HTTP_SERVER_START(":8089", "OnRequest") IF cErr != NIL ? "httpserver:", cErr ENDIF RETURN NIL // hReq fields (set by httpserver/server.go buildRequestHash): // method, path, query, headers (hash), body, remote_addr // // Reply with a JSON envelope listing every field plus a roundtripped // header so we know the hash walk is intact. FUNCTION OnRequest( hReq ) LOCAL hPayload := {; "ok" => .t.,; "method" => hReq[ "method" ],; "path" => hReq[ "path" ],; "query" => hReq[ "query" ],; "body_len" => Len( hReq[ "body" ] ),; "remote_addr" => hReq[ "remote_addr" ],; "user_agent" => hb_HGetDef( hReq[ "headers" ], "user-agent", "?" ); } RETURN {; "status" => 200,; "headers" => { "Content-Type" => "application/json; charset=utf-8" },; "body" => hb_jsonEncode( hPayload ); }