Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:34:50+00:00 2026-05-31T17:34:50+00:00

This is a pretty esoteric issue that I can’t produce a small test case

  • 0

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.

I have code like this (using restify):

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();
    });
});

When I hit this server using CURL, this works great. But when I hit it with XMLHttpRequest, I get one less "from inside" log line than I do "from outside" log lines. It seems one of the data events is getting lost, despite my best efforts to pause ASAP.


Here is the CURL command I am using:

curl -X PUT -T file.pdf http://localhost:7070/whatever -v

And here is the XMLHttpRequest code (works in recent versions of Chrome):

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);

One notable difference is that CURL seems to send Expect: 100-continue before uploading, whereas XMLHttpRequest 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:34:52+00:00Added an answer on May 31, 2026 at 5:34 pm

    Somewhat predictably, this didn’t have anything to do with curl vs. XMLHttpRequest, but instead with the fact that serverRequest.pause is only advisory; it doesn’t actually pause right away. That is, it’s pretty much useless.

    So presumably in the CURL case the timing was nice enough that pause actually worked as expected, whereas in the XMLHttpRequest case the timing was off, and one of the "from outside" data events managed to slip through the “advisory” pause.

    There are apparently various fixes for this, discussed in the thread, but I’m still pretty shaky on this whole streams/buffers universe so I won’t try to recommend one in this answer.

    I’ve added a documentation pull request in the hopes nobody else tries to use pause assuming that it actually works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is pretty trivial, but I noticed on SO that instead of an offset
Ok I know jquery can do this pretty simply, but digging around I'm a
I came across this pretty cool wizard menu, but I can't figure out how
this pretty much is the thing. When in tinymce I press anything that is
This is pretty weird. I have my Profiler open and it obviously shows that
This is pretty interesting, this site runs a speed test and compares all of
So I'm using this pretty standard jquery plugin pattern whereby you can grab an
I'm kind of stuck with this pretty simple (I'm sure) jQuery/Javascript issue. Here's the
So I have this pretty large XML file (40MB) that I'll have to repeatedly
This is a pretty esoteric question, so just to make clear here from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.