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