comparison ngx_http_delay_body_filter_module.c @ 2:b049c3a0543e

Simplified for the code without buffered counter. The only new flag which needs to be set is rb->filter_need_buffering, which is mostly needed for HTTP/2, where it is not possible to delay request body processing when flow control is not used.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 25 Aug 2021 19:36:57 +0300
parents 7c2d64d9c656
children 53cbdb610633
comparison
equal deleted inserted replaced
1:7c2d64d9c656 2:b049c3a0543e
14 14
15 15
16 typedef struct { 16 typedef struct {
17 ngx_event_t event; 17 ngx_event_t event;
18 ngx_chain_t *out; 18 ngx_chain_t *out;
19 ngx_uint_t buffered;
20 } ngx_http_delay_body_ctx_t; 19 } ngx_http_delay_body_ctx_t;
21 20
22 21
23 static ngx_int_t ngx_http_delay_body_filter(ngx_http_request_t *r, 22 static ngx_int_t ngx_http_delay_body_filter(ngx_http_request_t *r,
24 ngx_chain_t *in); 23 ngx_chain_t *in);
103 return NGX_ERROR; 102 return NGX_ERROR;
104 } 103 }
105 104
106 ngx_http_set_ctx(r, ctx, ngx_http_delay_body_filter_module); 105 ngx_http_set_ctx(r, ctx, ngx_http_delay_body_filter_module);
107 106
108 #if 1 /* XXX */
109 r->request_body->filter_need_buffering = 1; 107 r->request_body->filter_need_buffering = 1;
110 #endif
111 } 108 }
112 109
113 if (ngx_chain_add_copy(r->pool, &ctx->out, in) != NGX_OK) { 110 if (ngx_chain_add_copy(r->pool, &ctx->out, in) != NGX_OK) {
114 return NGX_ERROR; 111 return NGX_ERROR;
115 } 112 }
132 ctx->event.handler = ngx_http_delay_body_event_handler; 129 ctx->event.handler = ngx_http_delay_body_event_handler;
133 ctx->event.data = r; 130 ctx->event.data = r;
134 ctx->event.log = r->connection->log; 131 ctx->event.log = r->connection->log;
135 132
136 ngx_add_timer(&ctx->event, conf->delay); 133 ngx_add_timer(&ctx->event, conf->delay);
137
138 ctx->buffered = 1;
139 #if 1 /* XXX */
140 r->request_body->buffered++;
141 #endif
142 } 134 }
143 135
144 return ngx_http_next_request_body_filter(r, NULL); 136 return ngx_http_next_request_body_filter(r, NULL);
145 }
146
147 if (ctx->buffered) {
148 ctx->buffered = 0;
149 #if 1 /* XXX */
150 r->request_body->buffered--;
151 #endif
152 } 137 }
153 138
154 rc = ngx_http_next_request_body_filter(r, ctx->out); 139 rc = ngx_http_next_request_body_filter(r, ctx->out);
155 140
156 for (cl = ctx->out; cl; /* void */) { 141 for (cl = ctx->out; cl; /* void */) {