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