Changeset 26e5e981299b93a275012a85ed2391e4a90605b7

Show
Ignore:
Timestamp:
03/03/09 17:42:44 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1236102164 +0000
git-parent:

[b76d645b5e2d35c8e83bfd0f5e85cb6dc9573531]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1236102164 +0000
Message:

first whack at gzip encoding, refs #99

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_http.c

    rbe05f9f r26e5e98  
    594594  return len; 
    595595} 
     596/* memgzip */ 
     597static int memgzip2(Bytef *dest, uLongf *destLen, 
     598                    const Bytef *source, uLong sourceLen, int level) { 
     599    z_stream stream; 
     600    int err; 
     601 
     602    memset(&stream, 0, sizeof(stream)); 
     603    stream.next_in = (Bytef*)source; 
     604    stream.avail_in = (uInt)sourceLen; 
     605    stream.next_out = dest; 
     606    stream.avail_out = (uInt)*destLen; 
     607    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 
     608 
     609    err = deflateInit2(&stream, level, Z_DEFLATED, 15+16, 8, 
     610                       Z_DEFAULT_STRATEGY); 
     611    if (err != Z_OK) return err; 
     612 
     613    err = deflate(&stream, Z_FINISH); 
     614    if (err != Z_STREAM_END) { 
     615        deflateEnd(&stream); 
     616        return err == Z_OK ? Z_BUF_ERROR : err; 
     617    } 
     618    *destLen = stream.total_out; 
     619 
     620    err = deflateEnd(&stream); 
     621    return err; 
     622} 
    596623static noit_boolean 
    597624_http_encode_chain(struct bchain *out, struct bchain *in, int opts) { 
    598625  /* implement gzip and deflate! */ 
    599626  if(opts & NOIT_HTTP_GZIP) { 
     627    uLongf olen; 
     628    olen = out->allocd - out->start; 
     629    if(Z_OK != memgzip2((Bytef *)(out->buff + out->start), &olen, 
     630                        (Bytef *)(in->buff + in->start), (uLong)in->size, 
     631                        9)) { 
     632      noitL(noit_error, "zlib compress2 error\n"); 
     633      return noit_false; 
     634    } 
     635    out->size += olen; 
    600636  } 
    601637  else if(opts & NOIT_HTTP_DEFLATE) { 
     
    633669 
    634670  ilen = in->size; 
    635   if(opts & NOIT_HTTP_GZIP) ilen = compressBound(ilen); 
     671  if(opts & NOIT_HTTP_GZIP) ilen = deflateBound(NULL, ilen); 
    636672  else if(opts & NOIT_HTTP_DEFLATE) ilen = compressBound(ilen); 
    637673  out = bchain_alloc(hexlen + 4 + ilen); 
  • src/stratcon_realtime_http.c

    r512f29e r26e5e98  
    377377    noit_http_response_status_set(ctx, 200, "OK"); 
    378378    noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED); 
     379    noit_http_response_option_set(ctx, NOIT_HTTP_GZIP); 
    379380    /*noit_http_response_option_set(ctx, NOIT_HTTP_DEFLATE);*/ 
    380381    noit_http_response_header_set(ctx, "Content-Type", "text/html");