Changeset 11116


Ignore:
Timestamp:
Aug 4, 2010, 8:57:08 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #3486 "add gzip compression support to RPC server" -- fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/rpc-server.c

    r10984 r11116  
    316316    const char * key = "Accept-Encoding";
    317317    const char * encoding = evhttp_find_header( req->input_headers, key );
    318     const int do_deflate = encoding && strstr( encoding, "deflate" );
    319 
    320     if( !do_deflate )
     318    const int do_compress = encoding && strstr( encoding, "gzip" );
     319
     320    if( !do_compress )
    321321    {
    322322        evbuffer_add( out, content, content_len );
     
    335335            server->stream.zfree = (free_func) Z_NULL;
    336336            server->stream.opaque = (voidpf) Z_NULL;
    337             deflateInit( &server->stream, Z_BEST_COMPRESSION );
     337            server->stream.data_type = Z_ASCII;
     338
     339            /* zlib's manual says: "Add 16 to windowBits to write a simple gzip header
     340             * and trailer around the compressed data instead of a zlib wrapper." */
     341            deflateInit2( &server->stream, Z_BEST_COMPRESSION, Z_DEFLATED, 15+16, 9, Z_DEFAULT_STRATEGY );
    338342        }
    339343
     
    354358            EVBUFFER_LENGTH( out ) = content_len - server->stream.avail_out;
    355359
    356             /* http://carsten.codimi.de/gzip.yaws/
    357                It turns out that some browsers expect deflated data without
    358                the first two bytes (a kind of header) and and the last four
    359                bytes (an ADLER32 checksum). This format can of course
    360                be produced by simply stripping these off. */
    361             if( EVBUFFER_LENGTH( out ) >= 6 ) {
    362                 EVBUFFER_LENGTH( out ) -= 4;
    363                 evbuffer_drain( out, 2 );
    364             }
    365 
    366360#if 0
    367             tr_ninf( MY_NAME, _( "Deflated response from %zu bytes to %zu" ),
    368                               content_len,
    369                               EVBUFFER_LENGTH( out ) );
     361            fprintf( stderr, "compressed response is %.2f of original (raw==%zu bytes; compressed==%zu)\n",
     362                             (double)EVBUFFER_LENGTH(out)/content_len,
     363                             content_len, EVBUFFER_LENGTH(out) );
    370364#endif
    371365            evhttp_add_header( req->output_headers,
    372                                "Content-Encoding", "deflate" );
     366                               "Content-Encoding", "gzip" );
    373367        }
    374368        else
Note: See TracChangeset for help on using the changeset viewer.