Cache immutable Wasm server configuration encoding
This commit is contained in:
+12
-6
@@ -7,6 +7,7 @@
|
||||
|
||||
#define __UCE_WASM_CORE__ 1
|
||||
#include "../lib/uce_lib.cpp"
|
||||
|
||||
#include "../lib/mysql-connector.h"
|
||||
#include "../lib/sqlite-connector.h"
|
||||
|
||||
@@ -799,19 +800,26 @@ void uce_wasm_core_reset_request()
|
||||
wasm_component_paths.clear();
|
||||
}
|
||||
|
||||
// Host pushes the UCEB2-encoded request context into a guest buffer
|
||||
// (uce_alloc) and applies it here; mirrors the native param population.
|
||||
int uce_wasm_apply_context(const char* buf, size_t len)
|
||||
// Host pushes the worker-cached immutable configuration followed by the
|
||||
// dynamic UCEB2 request context into one guest buffer.
|
||||
int uce_wasm_apply_context(const char* config_buf, size_t config_len, const char* context_buf, size_t context_len)
|
||||
{
|
||||
if(context == 0)
|
||||
uce_wasm_core_init();
|
||||
StringMap decoded_config;
|
||||
DValue decoded;
|
||||
String error;
|
||||
if(!ucb_decode(String(buf, len), decoded, &error))
|
||||
if(!ucb_decode_flat_string_map(String(config_buf, config_len), decoded_config, &error))
|
||||
{
|
||||
uce_host_log(3, error.data(), error.size());
|
||||
return(1);
|
||||
}
|
||||
if(!ucb_decode(String(context_buf, context_len), decoded, &error))
|
||||
{
|
||||
uce_host_log(3, error.data(), error.size());
|
||||
return(2);
|
||||
}
|
||||
wasm_server.config = std::move(decoded_config);
|
||||
wasm_request.call = std::move(decoded);
|
||||
DValue& applied = wasm_request.call;
|
||||
auto apply_map = [](DValue* source, StringMap& dest) {
|
||||
@@ -821,8 +829,6 @@ int uce_wasm_apply_context(const char* buf, size_t len)
|
||||
dest[key] = item.to_string();
|
||||
});
|
||||
};
|
||||
if(applied.key("server_config"))
|
||||
apply_map(applied.key("server_config"), wasm_server.config);
|
||||
apply_map(applied.key("params"), wasm_request.params);
|
||||
wasm_request.response_code = wasm_request.params["GATEWAY_INTERFACE"] != "" ?
|
||||
"Status: 200 OK" : "HTTP/1.1 200 OK";
|
||||
|
||||
Reference in New Issue
Block a user