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