f87a44
# ./pullrev.sh 1848298
f87a44
f87a44
http://svn.apache.org/viewvc?view=revision&revision=1848298
f87a44
f87a44
https://bugzilla.redhat.com/show_bug.cgi?id=1652493
f87a44
f87a44
--- mod_fcgid-2.3.9/modules/fcgid/fcgid_bridge.c
f87a44
+++ mod_fcgid-2.3.9/modules/fcgid/fcgid_bridge.c
f87a44
@@ -526,7 +526,8 @@
f87a44
 }
f87a44
 
f87a44
 static int add_request_body(request_rec *r, apr_pool_t *request_pool,
f87a44
-                            apr_bucket_brigade *output_brigade)
f87a44
+                            apr_bucket_brigade *output_brigade,
f87a44
+                            apr_off_t *body_length)
f87a44
 {
f87a44
     apr_bucket *bucket_input, *bucket_header;
f87a44
     apr_file_t *fd = NULL;
f87a44
@@ -729,22 +730,49 @@
f87a44
     }
f87a44
     APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_header);
f87a44
 
f87a44
+    *body_length = request_size;
f87a44
+    
f87a44
     return 0;
f87a44
 }
f87a44
 
f87a44
 int bridge_request(request_rec * r, int role, fcgid_cmd_conf *cmd_conf)
f87a44
 {
f87a44
-    apr_bucket_brigade *output_brigade;
f87a44
+    apr_bucket_brigade *output_brigade, *body_brigade;
f87a44
     apr_bucket *bucket_eos;
f87a44
-    char **envp = ap_create_environment(r->pool,
f87a44
-                                        r->subprocess_env);
f87a44
+    char **envp;
f87a44
     int rc;
f87a44
 
f87a44
     /* Create brigade for the request to fastcgi server */
f87a44
+    body_brigade
f87a44
+        = apr_brigade_create(r->pool, r->connection->bucket_alloc);
f87a44
     output_brigade =
f87a44
         apr_brigade_create(r->pool, r->connection->bucket_alloc);
f87a44
 
f87a44
-    /* Build the begin request and environ request, append them to output_brigade */
f87a44
+    /* In responder mode, handle the request body up front to ensure
f87a44
+     * the content-length is known (even if the request body is
f87a44
+     * chunked) and sent in the header. */
f87a44
+    if (role == FCGI_RESPONDER) {
f87a44
+        apr_off_t body_length;
f87a44
+        
f87a44
+        rc = add_request_body(r, r->pool, body_brigade, &body_length);
f87a44
+        if (rc) {
f87a44
+            return rc;
f87a44
+        }
f87a44
+
f87a44
+        if (body_length && !apr_table_get(r->headers_in, "Content-Length")) {
f87a44
+            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
f87a44
+                          "mod_fcgid: dechunked request body length %" APR_OFF_T_FMT,
f87a44
+                          body_length);
f87a44
+        
f87a44
+            apr_table_set(r->subprocess_env, "CONTENT_LENGTH",
f87a44
+                          apr_off_t_toa(r->pool, body_length));
f87a44
+            apr_table_unset(r->subprocess_env, "HTTP_TRANSFER_ENCODING");
f87a44
+        }
f87a44
+    }
f87a44
+
f87a44
+    envp = ap_create_environment(r->pool, r->subprocess_env);
f87a44
+          
f87a44
+    /* Build the begin request and environ request, add them to output_brigade */
f87a44
     if (!build_begin_block
f87a44
         (role, r, r->connection->bucket_alloc, output_brigade)
f87a44
         || !build_env_block(r, envp, r->connection->bucket_alloc,
f87a44
@@ -754,12 +782,8 @@
f87a44
         return HTTP_INTERNAL_SERVER_ERROR;
f87a44
     }
f87a44
 
f87a44
-    if (role == FCGI_RESPONDER) {
f87a44
-        rc = add_request_body(r, r->pool, output_brigade);
f87a44
-        if (rc) {
f87a44
-            return rc;
f87a44
-        }
f87a44
-    }
f87a44
+    /* Append the body output. */
f87a44
+    APR_BRIGADE_CONCAT(output_brigade, body_brigade);
f87a44
 
f87a44
     /* The eos bucket now */
f87a44
     bucket_eos = apr_bucket_eos_create(r->connection->bucket_alloc);