Decode request maps directly into Wasm workspaces
This commit is contained in:
+1
-41
@@ -154,47 +154,7 @@ bool wasm_backend_should_handle(Request& request, const String& entry_unit)
|
||||
// configured error page.
|
||||
String wasm_backend_serve(Request& request, const String& entry_unit, const String& handler = "render")
|
||||
{
|
||||
DValue ctx;
|
||||
auto copy_map = [&](const StringMap& source, const char* key) {
|
||||
for(auto& entry : source)
|
||||
ctx[key][entry.first] = entry.second;
|
||||
};
|
||||
copy_map(request.params, "params");
|
||||
copy_map(request.get, "get");
|
||||
copy_map(request.post, "post");
|
||||
copy_map(request.cookies, "cookies");
|
||||
copy_map(request.session, "session");
|
||||
ctx["session_id"] = request.session_id;
|
||||
ctx["session_name"] = request.session_name;
|
||||
ctx["session_loaded_hash"] = request.session_loaded_hash;
|
||||
ctx["entry_unit"] = entry_unit;
|
||||
// Raw request body: cli_input() parses a JSON CLI payload from context.in,
|
||||
// and serve_http handlers read it as req->in; carried into the workspace.
|
||||
ctx["in"] = request.in;
|
||||
// Configurable error pages read context.call["error"] (the error_info DValue
|
||||
// set natively in render_wasm_error_page). apply_context binds context.call to
|
||||
// the decoded ctx, so marshal the native request.call children across the
|
||||
// membrane — otherwise the error page renders with no error data.
|
||||
for(auto& entry : request.call._map)
|
||||
ctx[entry.first] = entry.second;
|
||||
// WebSocket event context: the workspace owns no connections, so the frame's
|
||||
// connection identity goes in and the handler's ws_send/ws_close dispatch
|
||||
// commands come back out (below) for the native broker to apply.
|
||||
if(handler == "websocket")
|
||||
{
|
||||
ctx["ws"]["connection_id"] = request.resources.websocket_connection_id;
|
||||
ctx["ws"]["scope"] = request.resources.websocket_scope;
|
||||
ctx["ws"]["opcode"] = (f64)request.resources.websocket_opcode;
|
||||
ctx["ws"]["binary"].set_bool(request.resources.websocket_is_binary);
|
||||
for(auto& id : request.resources.websocket_scope_connection_ids)
|
||||
{
|
||||
DValue v; v = id;
|
||||
ctx["ws"]["connections"].push(v);
|
||||
}
|
||||
ctx["ws"]["connection_state"] = request.connection;
|
||||
}
|
||||
|
||||
WasmResponse response = wasm_worker_serve(*g_wasm_worker, ctx, entry_unit, handler, &request);
|
||||
WasmResponse response = wasm_worker_serve(*g_wasm_worker, request, entry_unit, handler);
|
||||
request.stats.wasm_dispatch_us = response.dispatch_us;
|
||||
request.stats.wasm_workspace_complete_us = response.workspace_complete_us;
|
||||
request.stats.wasm_entry_invoke_us = response.entry_invoke_us;
|
||||
|
||||
Reference in New Issue
Block a user