Rev 33: Workaround Apache 2.0 hack. in file:///v/home/vila/src/plugins/webdav/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon May 7 12:59:43 BST 2007
At file:///v/home/vila/src/plugins/webdav/
------------------------------------------------------------
revno: 33
revision-id: v.ladeuil+lp at free.fr-20070507115942-7556w3g7958twdae
parent: v.ladeuil+lp at free.fr-20061205135628-crj2xjk032n12uq5
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: webdav
timestamp: Mon 2007-05-07 13:59:42 +0200
message:
Workaround Apache 2.0 hack.
* webdav.py:
(HttpDavTransport._append_by_head_put): Apache 2.0 do not send a
Content-Length header if the file exists but is empty. Work around
that hack but issue a mutter in case we encounter a buggy server
modified:
webdav.py webdav.py-20060816232542-enpjxth2743ttqpq-3
-------------- next part --------------
=== modified file 'webdav.py'
--- a/webdav.py 2006-12-05 13:56:28 +0000
+++ b/webdav.py 2007-05-07 11:59:42 +0000
@@ -245,6 +245,9 @@
raise InvalidHttpResponse(url,
'Unable to handle http code %d%s'
% (response.code, msg))
+ def _handle_common_errors(self, code, abspath):
+ if code == 404:
+ raise NoSuchFile(abspath)
def put_file(self, relpath, f, mode=None):
"""See Transport.put_file"""
@@ -554,12 +557,24 @@
response = self._head(relpath)
code = response.code
if code == 404:
- self.put_bytes(relpath, bytes)
relpath_size = 0
else:
mutter('response.headers [%r]' % response.headers)
- relpath_size = int(response.headers['Content-Length'])
+ # Consider the absence of Content-Length header as
+ # indicating an existing but empty file (Apache 2.0
+ # does this, and there is even a comment in
+ # modules/http/http_protocol.c calling that a *hack*,
+ # I agree, it's a hack. On the other hand if the file
+ # do not exist we get a 404, if the file does exist,
+ # is not empty and we get no Content-Length header,
+ # then the server is buggy :-/ )
+ relpath_size = int(response.headers.get('Content-Length', 0))
+ if relpath_size == 0:
+ mutter('if %s is not empty, the server is buggy' % relpath)
+ if relpath_size:
self._put_bytes_ranged(relpath, bytes, relpath_size)
+ else:
+ self.put_bytes(relpath, bytes)
return relpath_size
More information about the bazaar-commits
mailing list