mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Send uncompressed length in a custom header, if available, when using gzip transfer encoding
This commit is contained in:
parent
673eee9f5a
commit
da7ffcaf82
@ -595,6 +595,8 @@ class HTTPConnection(HTTPRequest):
|
||||
outheaders.set('Accept-Ranges', 'bytes', replace_all=True)
|
||||
if compressible and not ranges:
|
||||
outheaders.set('Content-Encoding', 'gzip', replace_all=True)
|
||||
if getattr(output, 'content_length', None):
|
||||
outheaders.set('Calibre-Uncompressed-Length', '%d' % output.content_length)
|
||||
output = GeneratedOutput(compress_readable_output(output.src_file), etag=output.etag)
|
||||
if output.content_length is not None and not compressible and not ranges:
|
||||
outheaders.set('Content-Length', '%d' % output.content_length, replace_all=True)
|
||||
|
@ -313,6 +313,7 @@ class TestHTTP(BaseTest):
|
||||
conn = server.connect()
|
||||
conn.request('GET', '/an_etagged_path', headers={'Accept-Encoding':'gzip'})
|
||||
r = conn.getresponse()
|
||||
self.ae(str(len(raw)), r.getheader('Calibre-Uncompressed-Length'))
|
||||
self.ae(r.status, httplib.OK), self.ae(zlib.decompress(r.read(), 16+zlib.MAX_WBITS), raw)
|
||||
|
||||
# Test getting a filesystem file
|
||||
|
Loading…
x
Reference in New Issue
Block a user