Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

ghost
Copy link

@ghost ghost commented Aug 30, 2012

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.

Before:

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

After:

db.saveDoc(someDoc, console.log);

/* Output:

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

*/

@ghost
Copy link
Author

ghost commented Aug 30, 2012

In the end listener, we added this debug code:

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

and it output this:

<html>
<head><title>411 Length Required</title></head>
<body bgcolor="white">
<center><h1>411 Length Required</h1></center>
<hr><center>nginx/1.2.3</center>
</body>
</html>

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.

@SlexAxton
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant