-
Notifications
You must be signed in to change notification settings - Fork 203
Closed
Labels
Description
It seems that combination of proxy_cache and sendfile results in an empty first argument of js_body_ filter.
Below is a minimal configuration that reproduces the issue:
load_module modules/ngx_http_js_module.so;
events {
worker_connections 1024;
}
http {
js_import lib.js;
proxy_cache_path /tmp/one levels=1 keys_zone=one:1m;
server {
listen 80;
proxy_cache one;
proxy_cache_valid any 1s;
location /origin/ {
return 200 ok\n;
}
location / {
proxy_pass http://127.0.0.1/origin/;
js_header_filter lib.headerFilter;
js_body_filter lib.bodyFilter buffer_type=buffer;
}
location /sf/ {
proxy_pass http://127.0.0.1/origin/;
sendfile on;
js_header_filter lib.headerFilter;
js_body_filter lib.bodyFilter buffer_type=buffer;
}
}
}
Where lib.js looks like:
var buffer = '';
function bodyFilter(r, data, flags) {
buffer += data;
if (flags.last)
return r.sendBuffer(buffer, flags);
}
function headerFilter(r) {
delete r.headersOut['Content-Length'];
}
export default { bodyFilter, headerFilter }
The results (second unexpected):
% curl -s http://127.0.0.1/ | wc -l
1
% curl -s http://127.0.0.1/sf/ | wc -l
0
Test was performed on Ubuntu 22.04 with packages from mainline repo at nginx.org
I hope these snippets are enough to catch the bug but don't hesitate to ask me about any additional info you need.
Thank you.
hedard