Fix http handler not found: pre-register via constructor #49
Vendored
+25
@@ -6,6 +6,31 @@
|
||||
#include <unistd.h>
|
||||
#include "el_runtime.h"
|
||||
|
||||
/* Pre-register the El HTTP handler so it is found by http_lookup_active()
|
||||
* regardless of whether the binary was linked with -rdynamic.
|
||||
*
|
||||
* el_runtime's http_set_handler resolves handler names via:
|
||||
* dlsym(RTLD_DEFAULT, "handle_request")
|
||||
* but dlsym only searches the dynamic symbol table, which only contains
|
||||
* user-defined symbols when the executable is linked with -rdynamic.
|
||||
* elb does not add -rdynamic, so dlsym returns NULL and routes return
|
||||
* "el-runtime: no http handler registered" even though http_serve is called.
|
||||
*
|
||||
* The fix: forward-declare handle_request here and register it directly
|
||||
* via el_runtime_register_handler before main() runs. This populates the
|
||||
* handler registry so http_lookup_active() finds it without needing dlsym.
|
||||
*/
|
||||
extern el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body);
|
||||
/* el_runtime_register_handler is intentionally not declared in el_runtime.h
|
||||
* ("extern lookup works since C symbols are global" — runtime comment). */
|
||||
extern void el_runtime_register_handler(const char* name,
|
||||
el_val_t (*fn)(el_val_t, el_val_t, el_val_t));
|
||||
|
||||
__attribute__((constructor))
|
||||
static void pre_register_http_handlers(void) {
|
||||
el_runtime_register_handler("handle_request", handle_request);
|
||||
}
|
||||
|
||||
el_val_t http_get_auth(el_val_t url, el_val_t tok) {
|
||||
char bearer[2048]; snprintf(bearer, sizeof(bearer), "Bearer %s", EL_CSTR(tok));
|
||||
el_val_t hdr_val = EL_STR(bearer);
|
||||
|
||||
Reference in New Issue
Block a user