js_body_filter sends empty body response when buffering is on
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1.6k
- Forks
- 239
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 10
Description
Hello.
I have a django application. Let's assume I have empty django project created by:
mkdir nginxtest
cd nginxtest/
python -m venv .venv
source .venv/bin/activate
pip install -U pip wheel django
django-admin startproject mytest . # See https://docs.djangoproject.com/en/3.2/intro/tutorial01/
./manage.py migrate
vim mytest/settings.py # Add: STATIC_ROOT = './static/'
./manage.py collectstatic
./manage.py runserver 0.0.0.0:8000
On nginx side I have the following configuration:
location / {
proxy_connect_timeout 10s;
#proxy_buffering off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_cache_valid 2m;
proxy_cache_valid 404 1m;
proxy_cache_key $uri;
proxy_cache_use_stale timeout updating error http_502 http_503;
proxy_cache proxy_cache;
js_header_filter utils.bohHeaderFilter;
js_body_filter utils.bohBodyFilter;
proxy_pass http://192.168.56.101:8000;
}
utils.js
function bohBodyFilter(r, data, flags) {
r.sendBuffer(data, flags);
}
function bohHeaderFilter(r) {
}
export default { bohHeaderFilter, bohBodyFilter };
So when I request resource with Content-Type!=text/html I get normal headers and empty body.
wget -v -S http://localhost/static/admin/css/fonts.css
If I comment js_header_filter and js_body_filter - everything is OK.
If I comment proxy_cache_use_stale WGET just freezes on getting body.
If I uncomment "proxy_buffering off;" - everything is OK.
nginx 1.20.1
njs 0.6.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the report with the shown nginx location configuration and utils.js filters, using nginx 1.20.1 and njs 0.6.1. Compare buffered requests with proxy_buffering off and with proxy_cache_use_stale disabled, then trace js_body_filter and r.sendBuffer behavior. Done means the response body is delivered correctly while buffering and the related cache settings remain enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nginx
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100