Welcome! Log In Create A New Profile

Advanced

ngx_http_script_run() question

Chris Newton via nginx-devel
July 18, 2022 11:04AM
I'm adding a variable that wants to provide an absolute URL to proxy_pass,
whose value is based in part on a database lookup - but if the search key
is not found in that database, my handler function is returning an
NGX_ERROR which seemed reasonable (there is no good default I can return),
so just causing a 500 error at that point is not unreasonable.

However, that also causes an error to be logged by ngx_http_proxy_eval()
for every request, which i'd like to avoid.

I can make a change to ngx_http_proxy_eval() :

*--- a/nginx/files/nginx/src/http/modules/ngx_http_proxy_module.c*

*+++ b/nginx/files/nginx/src/http/modules/ngx_http_proxy_module.c*

@@ -1098,9 +1098,10 @@ ngx_http_proxy_eval(ngx_http_request_t *r,
ngx_http_proxy_ctx_t *ctx,

ngx_url_t url;

ngx_http_upstream_t *u;



if (ngx_http_script_run(r, &proxy, plcf->proxy_lengths->elts, 0,

plcf->proxy_values->elts)

- == NULL)

+ == NULL || proxy.len == 0)

{

return NGX_ERROR;

}

although I think it might be good to make a more general fix - ie., have
ngx_http_script_run() return NULL if there was no output from the script:

*--- a/nginx/files/nginx/src/http/ngx_http_script.c*

*+++ b/nginx/files/nginx/src/http/ngx_http_script.c*

@@ -641,6 +641,9 @@ ngx_http_script_run(ngx_http_request_t *r, ngx_str_t
*value,

len += lcode(&e);

}



+ if (len == 0) {

+ return NULL;

+ }


Would that be a reasonable change to make ?

TIA

Chris
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

ngx_http_script_run() question

Chris Newton via nginx-devel 323 July 18, 2022 11:04AM

Re: ngx_http_script_run() question

Maxim Dounin 124 July 18, 2022 10:32PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 275
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready