@@ -328,6 +328,8 @@ modsecurity_write_body_cb(request_rec *rec, char *buf, unsigned int length)
328
328
{
329
329
ngx_buf_t * b ;
330
330
ngx_http_modsecurity_ctx_t * ctx ;
331
+ ngx_http_request_t * r ;
332
+ ngx_str_t * str ;
331
333
332
334
ctx = (ngx_http_modsecurity_ctx_t * ) apr_table_get (rec -> notes , NOTE_NGINX_REQUEST_CTX );
333
335
if (ctx == NULL ) {
@@ -336,7 +338,10 @@ modsecurity_write_body_cb(request_rec *rec, char *buf, unsigned int length)
336
338
337
339
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , ctx -> r -> connection -> log , 0 , "modSecurity: write_body_cb" );
338
340
339
- b = ctx -> r -> header_in ;
341
+ r = ctx -> r ;
342
+
343
+ /* set request body */
344
+ b = r -> header_in ;
340
345
341
346
if (b -> end - b -> pos < length ) {
342
347
b -> start = ngx_palloc (ctx -> r -> pool , length );
@@ -349,6 +354,18 @@ modsecurity_write_body_cb(request_rec *rec, char *buf, unsigned int length)
349
354
350
355
b -> last = ngx_cpymem (b -> pos , buf , length );
351
356
357
+ /* set content_length_n */
358
+ r -> headers_in .content_length_n = length ;
359
+
360
+ /* set headers_in.content_length */
361
+ str = & r -> headers_in .content_length -> value ;
362
+ str -> data = ngx_palloc (r -> pool , NGX_OFF_T_LEN );
363
+ if (str -> data == NULL ) {
364
+ return NGX_ERROR ;
365
+ }
366
+
367
+ str -> len = ngx_snprintf (str -> data , NGX_OFF_T_LEN , "%O" , length ) - str -> data ;
368
+
352
369
return APR_SUCCESS ;
353
370
}
354
371
@@ -417,7 +434,7 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r)
417
434
return NGX_ERROR ;
418
435
}
419
436
ngx_http_set_ctx (r , ctx , ngx_http_modsecurity );
420
-
437
+
421
438
if (r -> method == NGX_HTTP_POST ) {
422
439
/* Processing POST request body, should we process PUT? */
423
440
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 , "modSecurity: method POST" );
@@ -507,9 +524,9 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
507
524
return NULL ;
508
525
}
509
526
cln -> handler = ngx_http_modsecurity_cleanup ;
510
- ngx_memzero (cln -> data , sizeof (ngx_http_modsecurity_ctx_t ));
511
-
512
- ctx = cln -> data ;
527
+ ngx_memzero (cln -> data , sizeof (ngx_http_modsecurity_ctx_t ));
528
+
529
+ ctx = cln -> data ;
513
530
ctx -> r = r ;
514
531
515
532
if (r -> connection -> requests == 0 || ctx -> connection == NULL ) {
0 commit comments