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 8304305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:48:22+00:00 2026-06-08T17:48:22+00:00

A user can POST a document to our web service. We stream it elsewhere.

  • 0

A user can POST a document to our web service. We stream it elsewhere. But, at the end of the streaming, we need to be sure they didn’t lie about their Content-Length.

I assume if headerContentLength > realContentLength, the request will just wait for them to send the rest, eventually timing out. So that’s probably OK.

What about if headerContentLength < realContentLength? I.e. what if they keep sending data after they said they were done?

Is this taken care of by Node.js in any way? If not, what is a good way to check? I suppose I could just count up the bytes inside of some data event listeners—i.e., req.on("data", function (chunk) { totalBytes += chunk.length; }). That seems like a kludge though.

  • 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-06-08T17:48:23+00:00Added an answer on June 8, 2026 at 5:48 pm

    To check the actual length of the request, you have to add it up yourself. The data chunks are Buffers and they have a .length property that you can add up.

    If you specify the encoding with request.setEncoding(), your data chunks will be Strings instead. In that case, call Buffer.byteLength(chunk) to get the length. (Buffer is a global object in node.)

    Add up the total for each of your chunks and you’ll know how much data was sent.
    Here’s a rough (untested) example:

    https.createServer(function(req, res) {
        var expected_length = req.headers['content-length']; // I think this is a string ;)
        var actual_length = 0;
        req.on('data', function (chunk) {
            actual_length += chunk.length;
        });
        req.on('end', function() {
            console.log('expected: ' + expected_length + ', actual: ' + actual_length);
        });
    });
    

    Note: length refers to the maximum length of the Buffer‘s content, not the actual length. However, it works in this case because chunk buffers are always created at the exact correct length. Just be aware of that if you’re working with buffers somewhere else.

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

Sidebar

Related Questions

We have a website wherein a user can post information from our website to
I can post on group / page and user wall, but i don't want
Background XSL translates an XML document into a stylized web page. The user can
A user can post 4 times at most within a day. The difficulty is
I am working on social networking site where user can post photo and text
I am trying to setup a model where a user can post an advertisement
So on my site, a user can post a comment on 2 things: a
I'm creating some restful apis. There is a register api, user can POST an
In my application user can create post,however only the creator of the post can
A user can create a post. Posts have comments. A comment must belong to

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.