title: Bad Request: SendStream.error while sending file as response
body: <p>I am using Express with Node.</p>
  
  <p>I am attempting to send a PDF file as a response.</p>
  
  <p>This PDF file is first retrieved from another server using <code>http.request()</code> after which I wish to pipe it to the response.</p>
  
  <p>That is, when the browser makes a request for the route '<code>/PDF</code>, I carry out the following:</p>
  
  <p>app.get('/PDF', function (req, res) {
      var options = {
          host: host,
          path: path,
          method: 'GET',
          headers: {}
      };</p>
  
  <pre><code>var requesting = http.request(options, function (response) {
      var body = '';
  
      response.setEncoding('utf8');
  
      response.on('data', function (chunk) {
          body += chunk;
      });
      response.on('end', function () {
          var data = null;
          if (body) {
              try {
                  data = JSON.parse(body);
              }
              catch (err) {
                  data = body;
              }
          }
  
          res.sendfile(data);
      });
  });
  
  requesting.end();
  </code></pre>
  
  <p>});</p>
  
  <p>However, an error is thrown at <code>res.sendfile(data)</code>:</p>
  
  <pre><code>Error: Bad Request
      at SendStream.error (redacted/send.js:145:16)
      at SendStream.pipe (redacted/send.js:298:31)
      at ServerResponse.res.sendfile (redacted/response.js:339:8)
      at IncomingMessage.&lt;anonymous&gt; (redacted/api.js:289:17)
      at IncomingMessage.EventEmitter.emit (events.js:117:20)
      at _stream_readable.js:920:16
      at process._tickCallback (node.js:415:13)
  </code></pre>
  
  <p>How do I pass the HTTP GET request body (with content type 'application/pdf') to the browser?</p>