title: Sails.js: 200 response is sent before I want to send actual response
body: <p>Using Sails.js 1.2.3, I'm trying to send some data from a file as a response to GET request, either over HTTP or WebSockets. No matter if I access the file synchronously or asynchronously in the controller Sails sends 200 OK response before I'm able to send actual needed response. Initially I've tried piping the file to the response, unsuccessfully:</p>
  
  <pre><code>fn: async function() {
      var fs = require("fs");
      let filename = `foo.bar`;
      let file = require("path").resolve(
        sails.config.appPath,
        `.tmp/${filename}`
      );
      let filestream = fs.createReadStream(file);
      filestream.pipe(this.res);
  }
  </code></pre>
  
  <p>This way I get 'write after end' error and 200 OK response (with no data) is sent to client right before this error occurs.</p>
  
  <p>If I do it synchronously, like:</p>
  
  <pre><code>     ...
        var offset = 0;
        var chunkSize = 2048;
        var chunkBuffer = new Buffer(chunkSize);
  
        var fd = fs.openSync(file, "r");
        var chunk = fs.readSync(fd, chunkBuffer, 0, chunkSize, offset);
        this.res.send(chunkBuffer);
  </code></pre>
  
  <p>...the 200 OK response (with no data) is sent before I reach <code>this.res.send()</code>. There must be some automatic response handling I'm unaware of that sends 200 OK before I can do anything useful in the controller. How do I go about not sending any response until I explicitly say <code>this.res.send</code> or <code>this.res.end</code> after obtaining data I need to send? Thanks!</p>