@@ -328,6 +328,8 @@ modsecurity_write_body_cb(request_rec *rec, char *buf, unsigned int length)
328328{
329329 ngx_buf_t * b ;
330330 ngx_http_modsecurity_ctx_t * ctx ;
331+ ngx_http_request_t * r ;
332+ ngx_str_t * str ;
331333
332334 ctx = (ngx_http_modsecurity_ctx_t * ) apr_table_get (rec -> notes , NOTE_NGINX_REQUEST_CTX );
333335 if (ctx == NULL ) {
@@ -336,7 +338,10 @@ modsecurity_write_body_cb(request_rec *rec, char *buf, unsigned int length)
336338
337339 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , ctx -> r -> connection -> log , 0 , "modSecurity: write_body_cb" );
338340
339- b = ctx -> r -> header_in ;
341+ r = ctx -> r ;
342+
343+ /* set request body */
344+ b = r -> header_in ;
340345
341346 if (b -> end - b -> pos < length ) {
342347 b -> start = ngx_palloc (ctx -> r -> pool , length );
@@ -349,6 +354,18 @@ modsecurity_write_body_cb(request_rec *rec, char *buf, unsigned int length)
349354
350355 b -> last = ngx_cpymem (b -> pos , buf , length );
351356
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+
352369 return APR_SUCCESS ;
353370}
354371
@@ -417,7 +434,7 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r)
417434 return NGX_ERROR ;
418435 }
419436 ngx_http_set_ctx (r , ctx , ngx_http_modsecurity );
420-
437+
421438 if (r -> method == NGX_HTTP_POST ) {
422439 /* Processing POST request body, should we process PUT? */
423440 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)
507524 return NULL ;
508525 }
509526 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 ;
513530 ctx -> r = r ;
514531
515532 if (r -> connection -> requests == 0 || ctx -> connection == NULL ) {
0 commit comments