Welcome! Log In Create A New Profile

Advanced

RE: Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

March 31, 2018 10:40AM
> -----Original Message-----
> From: nginx-devel [mailto:nginx-devel-bounces@nginx.org] On Behalf Of Ryan Burn
> Sent: Friday, March 30, 2018 5:30 PM
> To: nginx-devel@nginx.org; robert@cryptobells.com
> Subject: Re: Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?
>
> The module is intended to support distributed tracing in a pluggable way.
>
> The key/values of the headers added are generated from the module.
> They're used to support cross process tracing
> (http://opentracing.io/documentation/pages/api/cross-process-tracing.html)
> so that the performance information recorded by this module can be linked to the performance information reported by any other code that processes the request.
>
> Since the specific headers values used to propagate the tracing context across processes vary by tracing system (for example zipkin uses B3 headers https://github.com/openzipkin/b3-propagation), jaeger uses headers like (uber-trace-id, uberctx-*, etc), I'd rather not have any of those details be exposed to the nginx configuration.
>
> Is there any way any way an arbitrary number of headers can be added without requiring the configuration writer to know anything about them?
>

A bit hacky, but what you can do is copy the function 'ngx_conf_handler' to your module (you can't use the existing one
since it's static...), then add a command handler -

static char *
ngx_http_my_proxy_set_header(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_array_t* old_args;
ngx_array_t args_arr;
ngx_str_t args[3] = {
ngx_string("proxy_set_header"),
ngx_string("header-name"),
ngx_string("header-value"),
};

args_arr.elts = &args;
args_arr.nelts = sizeof(args) / sizeof(args[0]);

old_args = cf->args;
cf->args = &args_arr;

if (ngx_conf_handler(cf, 0) != NGX_OK)
{
return NGX_CONF_ERROR;
}

cf->args = old_args;

return NGX_CONF_OK;
}

And add this to the commands array of your module -
{ ngx_string("my_proxy_set_header"),
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_NOARGS,
ngx_http_my_proxy_set_header,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },

nginx.conf will look like this -
location /something/ {
proxy_pass http://my_upstream;
my_proxy_set_header;
}

In this specific example, the my_proxy_set_header directive will essentially translate to 'proxy_set_header header-name header-value',
and you can repeat this multiple times to add multiple headers.

Eran

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

rnburn 843 March 28, 2018 03:48PM

Re: Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

Maxim Dounin 511 March 28, 2018 03:58PM

Re: Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

rnburn 450 March 28, 2018 04:18PM

Re: Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

Maxim Dounin 452 March 29, 2018 09:42AM

Re: Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

rnburn 506 March 29, 2018 02:08PM

Re: Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

Robert Paprocki 448 March 29, 2018 02:36PM

Re: Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

rnburn 631 March 30, 2018 10:32AM

RE: Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

erankor 674 March 31, 2018 10:40AM



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

Online Users

Guests: 150
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