Is it possible to add "headers" key in subrequest options?
For example:
{
args: "arg1=txt",
body: "request body",
method: "POST",
headers: {content_type: "application/json", authorization: "token", ...}
}
Hi @an0ma1ia,
Unfortunately, it is hard to correctly replace incoming headers in nginx. The main and the sub requests share incoming headers structure.
If you want to control the outgoing headers in the subrequest you can use the following directives in the subrequest location
1) proxy_set_header to set or override headers.
2) proxy_pass_request_headers off to drop all the headers of the main request.
In the future, we plan to introduce 'native' http client in njs, which will not rely upon nginx subrequests.
I use GET parameter to pass header value to the subrequest location where I set header by proxy_set_header. Exactly what you recommend. Works well but looks a bit strange.
Thank you for the clarification.
@xeioex
In the future, we plan to introduce 'native' http client in njs, which will not rely upon nginx subrequests.
Sounds great, but does it still rely upon current request, or is individual in process?
@hongzhidao
Sounds great, but does it still rely upon current request, or is individual in process?
It still will be linked to the current request, because njs context is linked to it. But, it will not depend heavily on nginx internal structures.
Most helpful comment
@hongzhidao
It still will be linked to the current request, because njs context is linked to it. But, it will not depend heavily on nginx internal structures.