Changeset 6820


Ignore:
Timestamp:
Oct 1, 2008, 3:53:56 PM (13 years ago)
Author:
charles
Message:

add support for compressing the content served by the rpc server -- rpc responses and clutch html/css/js files

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r6816 r6820  
    44http://trac.transmissionbt.com/query?group=component&milestone=1.40
    55- All Platforms
     6   + Rewritten bandwidth management code
    67   + Lazy bitfields
    7    + Rewritten bandwidth management code
     8   + Support compression when serving Web Interface content and RPC responses
    89- Mac
    910   + Option to automatically update the blocklist weekly
  • trunk/configure.ac

    r6797 r6820  
    6969PKG_CHECK_MODULES(OPENSSL, [openssl >= $OPENSSL_MINIMUM], , [CHECK_SSL()])
    7070PKG_CHECK_MODULES(LIBCURL, [libcurl >= $CURL_MINIMUM])
     71CHECK_ZLIB()
    7172
    7273AC_SYS_LARGEFILE
  • trunk/daemon/remote.c

    r6813 r6820  
    10571057    curl = curl_easy_init( );
    10581058    curl_easy_setopt( curl, CURLOPT_VERBOSE, debug );
     1059#ifdef HAVE_LIBZ
     1060    curl_easy_setopt( curl, CURLOPT_ENCODING, "deflate" );
     1061#endif
    10591062    curl_easy_setopt( curl, CURLOPT_USERAGENT,
    10601063                      MY_NAME "/" LONG_VERSION_STRING );
  • trunk/libtransmission/rpc-server.c

    r6819 r6820  
    1919#include <fcntl.h>     /* open */
    2020#include <unistd.h>    /* close */
     21
     22#ifdef HAVE_LIBZ
     23#include <zlib.h>
     24#endif
    2125
    2226#include <libevent/event.h>
     
    204208}
    205209
     210#ifdef HAVE_LIBZ
     211static void
     212compress_evbuf( struct evbuffer * evbuf )
     213{
     214    static struct evbuffer *tmp;
     215    static z_stream stream;
     216    static unsigned char buffer[2048];
     217   
     218    if( !tmp ) {
     219        tmp = evbuffer_new( );
     220        deflateInit( &stream, Z_BEST_COMPRESSION );
     221    }
     222
     223    deflateReset( &stream );
     224    stream.next_in = EVBUFFER_DATA(evbuf);
     225    stream.avail_in = EVBUFFER_LENGTH(evbuf);
     226
     227    do {
     228        stream.next_out = buffer;
     229        stream.avail_out = sizeof( buffer );
     230        if( deflate( &stream, Z_FULL_FLUSH ) == Z_OK )
     231            evbuffer_add( tmp, buffer, sizeof( buffer ) - stream.avail_out );
     232        else
     233            break;
     234    } while (stream.avail_out == 0);
     235
     236/*fprintf( stderr, "deflated response from %zu to %zu bytes\n", EVBUFFER_LENGTH( evbuf ), EVBUFFER_LENGTH( tmp ) );*/
     237    evbuffer_drain(evbuf, EVBUFFER_LENGTH(evbuf));
     238    evbuffer_add_buffer(evbuf, tmp);
     239}
     240#endif
     241
     242static void
     243maybe_deflate_response( struct evhttp_request * req, struct evbuffer * response )
     244{
     245#ifdef HAVE_LIBZ
     246    const char * accept_encoding = evhttp_find_header( req->input_headers, "Accept-Encoding" );
     247    const int do_deflate = accept_encoding && strstr( accept_encoding, "deflate" );
     248    if( do_deflate ) {
     249        evhttp_add_header( req->output_headers, "Content-Encoding", "deflate" );
     250        compress_evbuf( response );
     251    }
     252#endif
     253}
     254
    206255static void
    207256serve_file( struct evhttp_request * req,
     
    227276                              mimetype_guess(
    228277                                  path ) );
     278            maybe_deflate_response( req, buf );
    229279            evhttp_send_reply( req, HTTP_OK, "OK", buf );
    230280            evbuffer_free( buf );
     
    266316}
    267317
     318
    268319static void
    269320handle_rpc( struct evhttp_request * req,
     
    295346    buf = evbuffer_new( );
    296347    evbuffer_add( buf, response, len );
     348    maybe_deflate_response( req, buf );
    297349    evhttp_add_header( req->output_headers, "Content-Type",
    298350                       "application/json; charset=UTF-8" );
     
    329381{
    330382    struct tr_rpc_server * server = arg;
    331     fprintf( stderr, "%s:%d Got request: \"%s\"\n", __FILE__, __LINE__, req->uri );
    332383
    333384    if( req && req->evcon )
     
    395446        tr_free( user );
    396447    }
    397     fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ );
    398448}
    399449
     
    403453    tr_rpc_server * server  = vserver;
    404454
    405     fprintf( stderr, "%s:%d in startServer; current context is %p\n", __FILE__, __LINE__, server->httpd );
    406 
    407455    if( !server->httpd )
    408456    {
    409         int i;
    410457        server->httpd = evhttp_new( tr_eventGetBase( server->session ) );
    411         fprintf( stderr, "%s:%d in startServer; new context is %p\n", __FILE__, __LINE__, server->httpd );
    412         i = evhttp_bind_socket( server->httpd, "0.0.0.0", server->port );
    413         fprintf( stderr, "evhttp_bind_socket returned %d\n", i );
     458        evhttp_bind_socket( server->httpd, "0.0.0.0", server->port );
    414459        evhttp_set_gencb( server->httpd, handle_request, server );
    415460    }
  • trunk/third-party/macosx-libevent-config.h

    r5110 r6820  
    231231
    232232/* Version number of package */
    233 #define VERSION "1.4.1-beta"
     233#define VERSION "1.4.8-stable"
    234234
    235235/* Define to appropriate substitue if compiler doesnt have __func__ */
  • trunk/third-party/macosx-libevent-event-config.h

    r5110 r6820  
    238238
    239239/* Version number of package */
    240 #define _EVENT_VERSION "1.4.1-beta"
     240#define _EVENT_VERSION "1.4.8-stable"
    241241
    242242/* Define to appropriate substitue if compiler doesnt have __func__ */
Note: See TracChangeset for help on using the changeset viewer.