lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

when header_filter_by_lua_file run failed.

Open akf00000 opened this issue 9 months ago • 0 comments

server { listen 80; server_name test.com; header_filter_by_lua_file my_header_filter.lua; location / { proxy_pass http://u1; } }

if some mistake in my_header_filter.lua, the request just abort, and the $status log value is 200. I thank is batter to change it to 500, just like rewrite_by_lua_file.

/*  protected call user code */
rc = lua_pcall(L, 0, 1, 1);

lua_remove(L, 1);  /* remove traceback function */

#if (NGX_PCRE)
/* XXX: work-around to nginx regex subsystem */
ngx_http_lua_pcre_malloc_done(old_pool);
#endif

dd("rc == %d", (int) rc);

if (rc != 0) {
    /*  error occurred when running loaded code */
    err_msg = (u_char *) lua_tolstring(L, -1, &len);

    if (err_msg == NULL) {
        err_msg = (u_char *) "unknown reason";
        len = sizeof("unknown reason") - 1;
    }

    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                  "failed to run header_filter_by_lua*: %*s", len, err_msg);

    lua_settop(L, 0); /*  clear remaining elems on stack */
-   return NGX_ERROR;
+   return r->header_sent ? NGX_ERROR : NGX_HTTP_INTERNAL_SERVER_ERROR;
}

akf00000 avatar May 23 '24 09:05 akf00000