title: Terminating file upload to NodeJS backend causes Apache 502 Gateway Error
body: <p>I've got an Apache webserver proxying some requests to a NodeJS backend. When the user uploads a invalid file, my server terminates the request with an error message. While this works correctly when calling the NodeJS backend directly, a 502 Bad Gateway error (&quot;The proxy server received an invalid response from an upstream server.
  &quot;) is given when proxied through Apache.</p>
  <p>The NodeJS termination (req = request, res = response)</p>
  <pre><code>            req.pause()
              res.statusCode = 400
              res.setHeader('Content-Type', 'text/plain');
              res.end(&quot;Invalid Request: &quot; + e.message);
              req.destroy([&quot;Invalid Request: &quot; + e.message])
  </code></pre>
  <p>I'd like to immediately end the upload (to save time &amp; bandwidth), and send an error message to the client, so simply pausing the request doesn't work for me - it leaves the client hanging. Not setting &quot;Connection: close&quot; or destroying the socket causes upload to continue, even after res.end is called with the error message.</p>
  <p>I am seeing an &quot;http error before end of send, stop sending&quot; error in Apache, so it's pretty clear that Apache is treating this as a backend server fault, rather than a legitimate error message to be returned to the client. How do I fix this? I've done quite a bit of searching, but haven't found a clear answer.</p>
  <p>The current proxy code (not much):</p>
  <pre><code>ProxyPass /node http://127.0.0.1:3000/node
  </code></pre>
  <p>More code can be provided upon request.</p>