Ignore:
Timestamp:
01/20/12 02:26:06 (16 months ago)
Author:
sam
Message:

Toying around with gzipped data. Sending 9 MiB, getting 1.5 GiB in the browser.

Location:
trollforge/lastmeasure/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trollforge/lastmeasure/server/lmresource.h

    r640 r642  
    9797 
    9898    static Response Get(char const *resource, char const *query, 
    99                         char const *host, char const *agent) 
     99                        char const *host, char const *agent, int *flags) 
    100100    { 
    101101        /* Special case for server status (TODO) */ 
     
    113113                return Response(m_statics[i], MimeType(resource)); 
    114114            } 
     115        } 
     116 
     117        /* Special case for gzipped data -- just a test for now */ 
     118        if (!strcmp(resource, "/gnaa.txt")) 
     119        { 
     120            *flags |= 1; 
     121            return Response(std::string( 
     122                "\x1f\x8b\x08\x00\x7d\xb7\x18\x4f\x02\x03\xec\xd1" 
     123                "\x41\x0a\x80\x20\x10\x05\xd0\x7d\xe0\x1d\xbc\x8a" 
     124                "\xab\x56\xb5\xea\xfe\x67\x89\x10\x29\x4d\xc3\x4d" 
     125                "\xbb\x97\x04\x4e\xcc\x9f\xb2\x17\x96\x18\xd7\x3d" 
     126                "\xa5\xeb\x8e\xb1\xde\xe7\xab\x5f\x1d\x5b\x58\x4a" 
     127                "\x6f\x7e\x56\x57\xed\xa4\x52\xe5\x54\x3d\xaf\x9e" 
     128                "\x71\xbf\xe5\x59\xf5\x72\xfd\xce\x51\x6e\xd4\xd9" 
     129                "\x3f\xc1\x7f\xb9\xaf\xef\x9c\xf9\x13\x6d\xee\xed" 
     130                "\x37\x97\x2b\x8b" 
     131                "\x3f\x7f\xfe\xfc\xf9\xf3\xe7\xcf\x9f", 109), "text/plain"); 
    115132        } 
    116133 
  • trollforge/lastmeasure/server/lmserver.cpp

    r577 r642  
    249249    /* Now build the response */ 
    250250    std::stringstream response(""); 
    251     Response data = Resources::Get(resource, query, host, agent); 
     251    int flags = 0; 
     252    Response data = Resources::Get(resource, query, host, agent, &flags); 
    252253    response << "HTTP/1.1 200 OK\r\n" 
    253254             << "Date: " << Utils::Time() << "\r\n" 
    254              << "Server: " << Random::ServerName() << "\r\n" 
    255              << "Content-Length: " << data.first.length() << "\r\n" 
    256              //<< "Connection: Keep-Alive\r\n" 
     255             << "Server: " << Random::ServerName() << "\r\n"; 
     256 
     257    if (flags & 1) 
     258        response << "Content-Encoding: gzip\r\n"; 
     259    else 
     260        response << "Content-Length: " << data.first.length() << "\r\n"; 
     261 
     262    response //<< "Connection: Keep-Alive\r\n" 
    257263             << "Connection: Close\r\n" 
    258264             << "Content-Type: " << data.second << "\r\n" 
     
    262268    send(client, response.str().c_str(), response.str().length(), 0); 
    263269 
     270    /* Send gzipped data for fun. Not very useful yet */ 
     271    if (flags & 1) 
     272    { 
     273        char const *data = response.str().c_str() + response.str().length() - 9; 
     274        for (int i = 0; i < 800000; i++) 
     275            send(client, data, 9, 0); 
     276    } 
     277 
    264278    /* FIXME: we could reuse the connection here */ 
    265279    close(client); 
Note: See TracChangeset for help on using the changeset viewer.