Mercurial > hg > ngx_http_delay_body_filter_module
diff t/delay_body.t @ 1:7c2d64d9c656
Working delay body and tests.
Depends on rb->filter_need_buffering and rb->buffered, as well as
corresponding changes in the request body reading code to work.
Might not be the best solution, as current body reading code relies
on rb->buffered to be properly set at various stages. Notably,
rb->buffered must be cleared when calling the next filter, since
the save body filter relies on it. Possible future improvements:
implement last buffer checking in the save body filter instead of
checking for (rb->rest == 0 && !rb->buffered).
The code uses its own event to implement delay timer. To remove the timer
in case of abnormal request termination a cleanup handler is added. While
in theory it is possible to use a timer on c->read instead, this implies
additional changes to the request body reading code. Custom event was chosen
to reduce complexity of changes needed.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 20 Aug 2021 22:35:05 +0300 |
parents | a386f95c5ae9 |
children |
line wrap: on
line diff
--- a/t/delay_body.t +++ b/t/delay_body.t @@ -35,11 +35,19 @@ http { server { listen 127.0.0.1:8080; server_name localhost; + location / { delay_body 1s; add_header X-Time $request_time; proxy_pass http://127.0.0.1:8080/empty; } + + location /no { + delay_body 0s; + add_header X-Time $request_time; + proxy_pass http://127.0.0.1:8080/empty; + } + location /empty { return 200 "test response body\n"; } @@ -53,7 +61,7 @@ EOF ############################################################################### like(get_body('/', '123456'), qr/200 OK.*X-Time: 1/ms, 'delay'); -like(get_body('/empty', '123456'), qr/200 OK.*X-Time: 0/ms, 'no delay'); +like(get_body('/no', '123456'), qr/200 OK.*X-Time: 0/ms, 'no delay'); # pipelining