question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing `Content-Length` in headers may cause nginx 411 Length Required Error.

See original GitHub issue

I’m not sure this is a bug, but content-length should be prepared in headers so that server knows when the chunk datas end.

I fixed this in my own project about uploading a file by calling getLength() in headers, but this cause a lot time when sending a big file.

As I know, chrome added content-length before sending the whole post content.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yyfrankyycommented, Jun 23, 2013

Nothing special, this is my solution:

      var f = new formData()
      f.append('uploadfile', fs.createReadStream(file))
      f.append('formId', 1)
      f.getLength(function(err, length) {
        var token = qs.parse(url.parse(body.ErrMsg).query).token
        request.post({
            url: '/path/'
          , headers: {
              'content-length': length // 26xxxx
            }
        }, function(err, res, body) {
          var formId = body.match(/formId, '(\d+)'/)
          cb(err, formId && formId[1])
        })._form = f
      })

Here goes getLengthSync() version(wrong length)

      var f = new formData()
      f.append('uploadfile', fs.createReadStream(file))
      f.append('formId', 1)
      request.post({
          url: wx('/cgi-bin/uploadmaterial?cgi=uploadmaterial&type=0&t=iframe-uploadfile&lang=zh_CN&formId=1', token)
        , headers: {
            'content-length': f.getLengthSync() // 214
          }
      }, function(err, res, body) {
        var formId = body.match(/formId, '(\d+)'/)
        cb(err, formId && formId[1])
      })._form = f

0reactions
alexindigocommented, Jul 7, 2013

@yyfrankyy I updated Readme.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Fix the “411 Length Required” Error (4 Methods) - Kinsta
Fortunately, you can easily fix the “411 Length Required” error. This HTTP status code happens when the server requires a content-length header, ...
Read more >
Is there a way to avoid nginx 411 Content-Length required ...
Obviously you can't assume that the content continues until the connection is closed (which is what an absent content-length header implies), because the ......
Read more >
411 Length Required - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 411 Length Required client error response code indicates that the server refuses to accept the request ...
Read more >
nginx proxy_pass of PUT with no Content-Length header ...
I am having trouble with nginx proxy_pass and PUT without a Content-Length header returning a 411 error. What I run to test this:...
Read more >
411 Length Required error - NGINX - Ruby-Forum
My mistake on that last message. I read the wrong headers info. It seems ngninx reports no Content-Length header was sent but according...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found