-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synchronous version of ngx.fetch
#762
Comments
Well the use-case is simple, change response headers based on external service response, it seems that the only place that this can be done is in |
@s3rj1k Please, elaborate more, what header and what information you send to an external service. One possible workaround is to use r.subrequest() for the main request, modify the subrequest response asynchronously, send the modifies reply to the client. It works in some cases but it can be brittle in more complex configurations. |
I need to send response headers out to external service and that service will decide based on headers value if there is a need to modify them, so in this case I need that headers that would be sent out would be processed late in nginx filter chain (if I understand correctly nginx semantics). So doing something with headers during |
@xeioex Any news on that? P.S. This will benefit Nginx Unit, as for it there is no alternative (harder) ways of doing similar. |
Hi @s3rj1k, no progress on my side. Also, |
@s3rj1k |
buffering content inside JS runtime would impact performance vs doing same in C inside filter phase. |
@s3rj1k As I understand it, if you use subrequests for the main request to the backend(rather than fetch), then the njs module does not in fact buffer the response body. It's buffered by nginx (see subrequest_output_buffer_size). It will of course consume more memory naturally than regular proxy_pass on it's own due it's ability to do partial buffering / buffer reuse as the client consumes data, however this rarely matters unless responses are expected to be very large. Anyway I'd recommend benchmarking it to see if it fits your use-case if you have not done so, it's quite fast unless you start actually manipulating response body / perform complex logic in within js, from previous experience. |
Additional synchronous version of
ngx.fetch
or any other curl-like HTTP request-response function that can be used injs_*_filter
directive.Function should be as close as possible to async
ngx.fetch
but work as a blocking sync operation.The text was updated successfully, but these errors were encountered: