Ignore:
Timestamp:
May 8, 2009, 4:41:32 PM (13 years ago)
Author:
charles
Message:

(trunk libT) #2043: allow static files served by rpc-server to be cached

File:
1 edited

Legend:

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

    r8358 r8360  
    306306
    307307static void
     308add_time_header( struct evkeyvalq * headers, const char * key, time_t value )
     309{
     310    /* According to RFC 2616 this must follow RFC 1123's date format,
     311       so use gmtime instead of localtime... */
     312    char buf[1024];
     313    struct tm tm = *gmtime( &value );
     314    strftime( buf, sizeof( buf ), "%a, %d %b %Y %H:%M:%S GMT", &tm );
     315    evhttp_add_header( headers, key, buf );
     316}
     317
     318static void
    308319serve_file( struct evhttp_request * req,
    309320            struct tr_rpc_server *  server,
     
    334345        {
    335346            struct evbuffer * out;
     347            const time_t now = time( NULL );
    336348
    337349            errno = error;
    338350            out = tr_getBuffer( );
    339             evhttp_add_header( req->output_headers, "Content-Type",
    340                                mimetype_guess( filename ) );
     351            evhttp_add_header( req->output_headers, "Content-Type", mimetype_guess( filename ) );
     352            add_time_header( req->output_headers, "Date", now );
     353            add_time_header( req->output_headers, "Expires", now+(24*60*60) );
    341354            add_response( req, server, out, content, content_len );
    342355            evhttp_send_reply( req, HTTP_OK, "OK", out );
Note: See TracChangeset for help on using the changeset viewer.