http: Populate query and headers for handler.js like we used to.

This commit is contained in:
Cory McWilliams 2024-11-04 21:46:38 -05:00
parent a84f850e91
commit 259f92c53b

View File

@ -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 path_value = JS_NewString(context, path);
JSValue package_owner_value = JS_NewString(context, package_owner); JSValue package_owner_value = JS_NewString(context, package_owner);
JSValue app_value = JS_NewString(context, app); 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[] = { JSValue args[] = {
response, response,
handler_blob_id, handler_blob_id,
path_value, path_value,
JS_UNDEFINED, query_value,
JS_UNDEFINED, headers,
package_owner_value, package_owner_value,
app_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); tf_util_report_error(context, result);
JS_FreeValue(context, result); JS_FreeValue(context, result);
JS_FreeValue(context, headers);
JS_FreeValue(context, query_value);
JS_FreeValue(context, app_value); JS_FreeValue(context, app_value);
JS_FreeValue(context, package_owner_value); JS_FreeValue(context, package_owner_value);
JS_FreeValue(context, handler_blob_id); JS_FreeValue(context, handler_blob_id);