Opened 4 years ago

Closed 4 years ago

#2055 closed defect (wontfix)

Using addition_filter and changing the added file: still returning "304 Not Modified"

Reported by: sijanec@… Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.19.x
Keywords: Cc:
uname -a: Linux kondenzator 5.3.0-59-generic #53~18.04.1-Ubuntu SMP Thu Jun 4 14:58:26 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: a@kondenzator:~[1]$ /tmp/nginx/objs/nginx -V
nginx version: nginx/1.19.3
built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
configure arguments: --with-http_addition_module



I have just stumbled upon a nginx bug. When using add_before_body and/or add_after_body commands from ngx_http_addition_filter_module, the server will respond with "304 Not Modified" even if the added file has changed.

After investigation I figured out that this error could be applied to everything that uses ngx_http_subrequest to gather data. The request structure will remain with the same last_modified_time even if the subrequest contains data that was modified after this time. The solution to this problem would be to overwrite the request structure headers_out.last_modified_time with the last_modified_time in the structure, generated by ngx_http_subrequest, if it's in the future, but that would not be enough.

The problem is that ngx_http_subrequest does not populate the request struct, specified as it's fourth argument, with headers_out.last_modified_time, it stays at -1, but that wouldn't help very much in this particular case.

Even setting the headers_out.last_modified_time to -1 in addition_filter_module would not work and would not fix the issue, because the filter modules do not execute before not_modified module (nginx/auto/modules:142).

Well, at last resort, the not_modified module could load configuration of addition_filter module and, if addition is to be done, return to the next module. But that would not work either; the not_modified module source is included before the addition_filter so it's module struct and relying configurations are not available at the time of compilation.

Proof of bug: Run nginx with attached nginx.conf and create files /tmp/add.html and /tmp/index.html with some content. Load http://localhost:8080/ in a modern Firefox browser. Then change the file /tmp/add.html and nginx will proceed to report "304 Not Modified" and your browser's copy will after page refresh remain with the old /tmp/add.html file added at the beginning of the response.


Attachments (1)

nginx.conf (411 bytes ) - added by sijanec@… 4 years ago.

Download all attachments as: .zip

Change History (3)

by sijanec@…, 4 years ago

Attachment: nginx.conf added

comment:1 by sijanec@…, 4 years ago

Sorry, but it looks like I've incorrectly tagged the "component" property of this ticket with "documentation". Moderators, please change it to the appropriate value.


comment:2 by Maxim Dounin, 4 years ago

Component: documentationnginx-module
Resolution: wontfix
Status: newclosed

That's the expected behaviour of the addition filter, as it is expected to be used for non-essential additions. See detailed response here.

Note: See TracTickets for help on using tickets.