mirror of
https://github.com/transmission/transmission
synced 2025-02-21 21:57:01 +00:00
(trunk libT) #3486 "add gzip compression support to RPC server" -- fixed.
This commit is contained in:
parent
1632692539
commit
ad2cf3c394
1 changed files with 11 additions and 17 deletions
|
@ -315,9 +315,9 @@ add_response( struct evhttp_request * req,
|
|||
#else
|
||||
const char * key = "Accept-Encoding";
|
||||
const char * encoding = evhttp_find_header( req->input_headers, key );
|
||||
const int do_deflate = encoding && strstr( encoding, "deflate" );
|
||||
const int do_compress = encoding && strstr( encoding, "gzip" );
|
||||
|
||||
if( !do_deflate )
|
||||
if( !do_compress )
|
||||
{
|
||||
evbuffer_add( out, content, content_len );
|
||||
}
|
||||
|
@ -334,7 +334,11 @@ add_response( struct evhttp_request * req,
|
|||
server->stream.zalloc = (alloc_func) Z_NULL;
|
||||
server->stream.zfree = (free_func) Z_NULL;
|
||||
server->stream.opaque = (voidpf) Z_NULL;
|
||||
deflateInit( &server->stream, Z_BEST_COMPRESSION );
|
||||
server->stream.data_type = Z_ASCII;
|
||||
|
||||
/* zlib's manual says: "Add 16 to windowBits to write a simple gzip header
|
||||
* and trailer around the compressed data instead of a zlib wrapper." */
|
||||
deflateInit2( &server->stream, Z_BEST_COMPRESSION, Z_DEFLATED, 15+16, 9, Z_DEFAULT_STRATEGY );
|
||||
}
|
||||
|
||||
server->stream.next_in = (Bytef*) content;
|
||||
|
@ -353,23 +357,13 @@ add_response( struct evhttp_request * req,
|
|||
{
|
||||
EVBUFFER_LENGTH( out ) = content_len - server->stream.avail_out;
|
||||
|
||||
/* http://carsten.codimi.de/gzip.yaws/
|
||||
It turns out that some browsers expect deflated data without
|
||||
the first two bytes (a kind of header) and and the last four
|
||||
bytes (an ADLER32 checksum). This format can of course
|
||||
be produced by simply stripping these off. */
|
||||
if( EVBUFFER_LENGTH( out ) >= 6 ) {
|
||||
EVBUFFER_LENGTH( out ) -= 4;
|
||||
evbuffer_drain( out, 2 );
|
||||
}
|
||||
|
||||
#if 0
|
||||
tr_ninf( MY_NAME, _( "Deflated response from %zu bytes to %zu" ),
|
||||
content_len,
|
||||
EVBUFFER_LENGTH( out ) );
|
||||
fprintf( stderr, "compressed response is %.2f of original (raw==%zu bytes; compressed==%zu)\n",
|
||||
(double)EVBUFFER_LENGTH(out)/content_len,
|
||||
content_len, EVBUFFER_LENGTH(out) );
|
||||
#endif
|
||||
evhttp_add_header( req->output_headers,
|
||||
"Content-Encoding", "deflate" );
|
||||
"Content-Encoding", "gzip" );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue