title: Apache returns 502 Bad Gateway with mod_proxy and large file
body: <p>I am seeing a problem when sending a file through Apache configured as proxy to a local application using the Mongoose webserver.</p>
  
  <p>My setup:</p>
  
  <blockquote>
    <p>Apache (port 80) &lt;-> mod_proxy &lt;-> Mongoose (port 9090)</p>
  </blockquote>
  
  <p>mod_proxy is configured to transfer certain URLs from port 80 to localhost:9090.</p>
  
  <p>Mongoose only accepts authenticated responses. This works OK for normal (small) requests. With large file transfers however Apache returns a 502 Bad Gateway response.</p>
  
  <p>What happens (well, actually just my analysis of what happens) is that when our client (a .net client, expect 100 enabled) tries to send a file it sends the headers followed directly by the contents of the file.</p>
  
  <p>Mongoose receives the headers of the transfer, detects that it is not authenticated and returns a 401 Unauthorized and closes the connection. Now Apache (which is still receiving and processing the file transfer)  cannot forward the data any more and returns a 502 Bad Gateway (The proxy server received an invalid response from an upstream server).</p>
  
  <p>When sniffing on the external interface I see that the .net client sends the headers, followed within 20 msec by the contents, without receiving a 100 Continue. When the receive is finished Apache returns the 502.</p>
  
  <p>When sniffing the internal interface I see that the header and body are combined into one tcp packet of 16384 bytes. Mongoose replies within a few msecs with the 401 and closes the connection. </p>
  
  <p>It looks like Apache detects the close of the connection but ignores the 401 and does not forward this. Is there a possibility to have Apache correctly forward the 401 instead of replying with the 502?</p>
  
  <p>For the moment I changed our application to just read all data from the connection if a 401 is detected, but this is just a workaround as this comes down to sending the complete file twice. As the files can be hundreds of megabytes this can give quite some stress on our system.</p>
  
  <p>We are using Apache 2.2.9 (Debian) on an ARM system.</p>