13
13
#include "ngx_http_srcache_fetch.h"
14
14
#include "ngx_http_srcache_store.h"
15
15
#include "ngx_http_srcache_util.h"
16
+ #include <nginx.h>
16
17
17
18
18
19
static ngx_int_t ngx_http_srcache_fetch_subrequest (ngx_http_request_t * r ,
@@ -24,6 +25,8 @@ static ngx_int_t ngx_http_srcache_test_not_modified(ngx_http_request_t *r);
24
25
25
26
static ngx_int_t ngx_http_srcache_test_precondition (ngx_http_request_t * r );
26
27
28
+ static void ngx_http_srcache_post_read_body (ngx_http_request_t * r );
29
+
27
30
28
31
ngx_int_t
29
32
ngx_http_srcache_access_handler (ngx_http_request_t * r )
@@ -124,6 +127,15 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
124
127
return NGX_AGAIN ;
125
128
}
126
129
130
+ if (ctx -> waiting_request_body ) {
131
+ return NGX_AGAIN ;
132
+ }
133
+
134
+ if (ctx -> request_body_done == 1 ) {
135
+ ctx -> request_body_done = 0 ;
136
+ goto do_fetch_subrequest ;
137
+ }
138
+
127
139
if (ctx -> request_done ) {
128
140
dd ("request done" );
129
141
@@ -242,6 +254,28 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
242
254
243
255
dd ("running phase handler..." );
244
256
257
+ if (!r -> request_body ) {
258
+ dd ("reading request body: ctx = %p" , ctx );
259
+
260
+ rc = ngx_http_read_client_request_body (r ,
261
+ ngx_http_srcache_post_read_body );
262
+ if (rc == NGX_ERROR || rc > NGX_OK ) {
263
+ #if (nginx_version < 1002006 ) \
264
+ || (nginx_version >= 1003000 && nginx_version < 1003009 )
265
+ r -> main -> count -- ;
266
+ #endif
267
+ return rc ;
268
+ }
269
+
270
+ if (rc == NGX_AGAIN ) {
271
+ ctx -> waiting_request_body = 1 ;
272
+ return NGX_AGAIN ;
273
+ }
274
+
275
+ /* rc == NGX_OK */
276
+ }
277
+
278
+ do_fetch_subrequest :
245
279
/* issue a subrequest to fetch cached stuff (if any) */
246
280
247
281
rc = ngx_http_srcache_fetch_subrequest (r , conf , ctx );
@@ -497,4 +531,33 @@ ngx_http_srcache_test_precondition(ngx_http_request_t *r)
497
531
NGX_HTTP_PRECONDITION_FAILED );
498
532
}
499
533
534
+
535
+ static void
536
+ ngx_http_srcache_post_read_body (ngx_http_request_t * r )
537
+ {
538
+ ngx_http_srcache_ctx_t * ctx ;
539
+
540
+ ctx = ngx_http_get_module_ctx (r , ngx_http_srcache_filter_module );
541
+
542
+ dd ("post read: ctx=%p" , ctx );
543
+
544
+ ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
545
+ "srcache post read for the access phase: wait:%ud c:%ud" ,
546
+ (unsigned ) ctx -> waiting_request_body , r -> main -> count );
547
+
548
+ r -> write_event_handler = ngx_http_core_run_phases ;
549
+
550
+ #if defined(nginx_version ) && nginx_version >= 8011
551
+ r -> main -> count -- ;
552
+ #endif
553
+
554
+ dd ("c:%u" , r -> main -> count );
555
+
556
+ if (ctx -> waiting_request_body ) {
557
+ ctx -> request_body_done = 1 ;
558
+ ctx -> waiting_request_body = 0 ;
559
+ ngx_http_core_run_phases (r );
560
+ }
561
+ }
562
+
500
563
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */
0 commit comments