lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

_request() does not set the Content-Length when there is no content #139

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When I try to create a couchdb database I got:

ServerError: (411, '<html>\r\n<head><title>411 Length 
Required</title></head>\r\n<body bgcolor="white">\r\n<center><h1>411 Length 
Required</h1></center>\r\n<hr><center>nginx/0.7.62</center>\r\n</body>\r\n</html
>\r\n')

In /usr/lib/pymodules/python2.6/couchdb/client.py we need to add the 
Content-Lenght even if we don't have data

Instead of

        if content is not None:
            if not isinstance(content, basestring):
                body = json.encode(content).encode('utf-8')
                headers.setdefault('Content-Type', 'application/json')
            else:
                body = content
            headers.setdefault('Content-Length', str(len(body)))

we need

        if content is not None:
            if not isinstance(content, basestring):
                body = json.encode(content).encode('utf-8')
                headers.setdefault('Content-Type', 'application/json')
            else:
                body = content
            headers.setdefault('Content-Length', str(len(body)))
        else:
            headers.setdefault('Content-Length', '0')

Original issue reported on code.google.com by adiroi...@gmail.com on 29 Jun 2010 at 1:33

GoogleCodeExporter commented 8 years ago
Meh, I think nginx is at fault here. What kind of request are you doing here?

Original comment by djc.ochtman on 29 Jun 2010 at 1:39

GoogleCodeExporter commented 8 years ago
I am trying to create a database.

Original comment by adiroi...@gmail.com on 29 Jun 2010 at 3:38

GoogleCodeExporter commented 8 years ago
It doesn't seem unreasonable to send a "Content-Length: 0" header if there's no 
content, and it does fix this particular problem.

However, as far as I can tell, nginx does not support chunked encoding so the 
proxy is likely to fail again if you start sending attachments.

Original comment by matt.goo...@gmail.com on 29 Jun 2010 at 4:16

GoogleCodeExporter commented 8 years ago
Feel free to mark this bug as invalid.

I have just encountered this problem and try to work around it.

Cheers

Original comment by adiroi...@gmail.com on 29 Jun 2010 at 9:12

GoogleCodeExporter commented 8 years ago
Actually, regardless of whether attachments will work with nginx, I think we 
should include a "Content-Length: 0" header. See 
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13.

Original comment by matt.goo...@gmail.com on 8 Jul 2010 at 2:43

GoogleCodeExporter commented 8 years ago
Fixed in r39467749fc60.

Original comment by matt.goo...@gmail.com on 8 Jul 2010 at 8:11