From 259f92c53bdf5edb1403161a5b371c496058ae71 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 4 Nov 2024 21:46:38 -0500 Subject: [PATCH] http: Populate query and headers for handler.js like we used to. --- src/httpd.js.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/httpd.js.c b/src/httpd.js.c index 4eb52592..2278f0d8 100644 --- a/src/httpd.js.c +++ b/src/httpd.js.c @@ -1134,13 +1134,22 @@ static void _httpd_call_app_handler(tf_ssb_t* ssb, tf_http_request_t* request, c JSValue path_value = JS_NewString(context, path); JSValue package_owner_value = JS_NewString(context, package_owner); JSValue app_value = JS_NewString(context, app); + JSValue query_value = request->query ? JS_NewString(context, request->query) : JS_UNDEFINED; + + JSValue headers = JS_NewObject(context); + for (int i = 0; i < request->headers_count; i++) + { + char name[256] = ""; + snprintf(name, sizeof(name), "%.*s", (int)request->headers[i].name_len, request->headers[i].name); + JS_SetPropertyStr(context, headers, name, JS_NewStringLen(context, request->headers[i].value, request->headers[i].value_len)); + } JSValue args[] = { response, handler_blob_id, path_value, - JS_UNDEFINED, - JS_UNDEFINED, + query_value, + headers, package_owner_value, app_value, }; @@ -1149,6 +1158,8 @@ static void _httpd_call_app_handler(tf_ssb_t* ssb, tf_http_request_t* request, c tf_util_report_error(context, result); JS_FreeValue(context, result); + JS_FreeValue(context, headers); + JS_FreeValue(context, query_value); JS_FreeValue(context, app_value); JS_FreeValue(context, package_owner_value); JS_FreeValue(context, handler_blob_id);