When using nginx as a proxy, saveDoc fails due to missing content length #44

wants to merge 3 commits into


None yet

2 participants


We're using nginx to load-balance to our couch installs.

When using saveDoc, we get HTTP 411 back from the proxy (and worse, the saveDoc callback just gets called with no args). This patch adds content length to the request if it's missing.


db.saveDoc(someDoc, console.log); // Outputs { '0': {} } and someDoc is not saved.


db.saveDoc(someDoc, console.log);

/* Output:

{ '0': {},
{ ok: true,
id: '4eb6896f8e5fe31ab5eeba0ebc8e3cf7',
rev: '1-e2c7016a5c44d76c9c91b8ca30d7b6c5' } }



In the end listener, we added this debug code:

request.addListener("response", function(res) {
      var buffer = '';
      res.setEncoding(options.responseEncoding || 'utf8');
        .addListener('data', function(chunk) {
          buffer += (chunk || '');
        .addListener('end', function() {

and it output this:

<head><title>411 Length Required</title></head>
<body bgcolor="white">
<center><h1>411 Length Required</h1></center>

And the saveDoc callback was then called with no args. I think it should have been called either with that text or with a JSON parse error. This patch doesn't address this. Maybe non-2xx replies should throw? Different issue though.


Was having this same issue and this cleared it up. Just as a heads up or whatever . Thanks!


This needs to be Buffer.byteLength(options.data, 'utf8') or utf8 characters break the request length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment