title: NodeJS stream pausing/resuming does not work with XMLHttpRequest, but works with curl?
body: <p>This is a pretty esoteric issue that I can't produce a small test case for, so sorry in advance. But maybe someone has run into something like it previously.</p>
  
  <p>I have code like this (using restify):</p>
  
  <pre><code>server.put("/whatever", function (serverRequest, serverResponse, next) {
      serverRequest.pause();
  
      serverRequest.on("data", function (chunk) {
          console.log("from outside", chunk);
      });
  
      doSomeAsyncStuff(function (err) {
          serverRequest.on("data", function (chunk) {
              console.log("from inside", chunk);
          });
          serverRequest.on("end", function () {
              next();
          });
  
          serverRequest.resume();
      });
  });
  </code></pre>
  
  <p>When I hit this server using CURL, this works great. But when I hit it with XMLHttpRequest, I get one less <code>"from inside"</code> log line than I do <code>"from outside"</code> log lines. It seems one of the data events is getting lost, despite my best efforts to pause ASAP.</p>
  
  <hr>
  
  <p>Here is the CURL command I am using:</p>
  
  <pre><code>curl -X PUT -T file.pdf http://localhost:7070/whatever -v
  </code></pre>
  
  <p>And here is the <code>XMLHttpRequest</code> code (works in recent versions of Chrome):</p>
  
  <pre><code>var arrayBuffer = fromElsewhere();
  var xhr = new XMLHttpRequest();
  
  xhr.open("PUT", "http://localhost:7070/whatever");
  xhr.setRequestHeader("Content-Length", arrayBuffer.byteLength);
  xhr.setRequestHeader("Content-Type", "application/pdf");
  xhr.send(arrayBuffer);
  </code></pre>
  
  <p>One notable difference is that CURL seems to send <code>Expect: 100-continue</code> before uploading, whereas <code>XMLHttpRequest</code> does not. I tried adding that header manually but of course it didn't actually do much (i.e. Chrome did not wait for a response, it just sent up all the PDF data along with the original request). Even so, I don't know why this would effect things.</p>