title: Cancel a file download/request on node.js http.Client based on file size
body: <p>I made a function on node.js to start a file download but I want to create a rule where the function checks the file size before downloading the data.</p>
  
  <p>I got the response headers and checked the size but I dont know how to cancel everything withou transferring the actual data/body. Maybe there is a way to transfer only the headers first and the, if match my rule, I can fire another request to do the download.</p>
  
  <p>Here is a fragment of my code:</p>
  
  <pre><code>request.on('response', function(response) {
          var filesize = response.headers['content-length'];
          console.log("File size " + filename + ": " + filesize + " bytes.");
          response.pause();
          if (filesize &gt;= 50000) {
              // WHAT TO PUT HERE TO CANCEL THE DOWNLOAD?
              console.log("Download cancelled. File too big.");
          } else {
              response.resume();
          }
          //Create file and write the data chunks to it
  </code></pre>
  
  <p>Thanks.</p>