Blame SOURCES/mod_fcgid-2.3.9-r1848298.patch

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