Changeset 26e5e981299b93a275012a85ed2391e4a90605b7
- Timestamp:
- 03/03/09 17:42:44
(4 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
| rbe05f9f |
r26e5e98 |
|
| 594 | 594 | return len; |
|---|
| 595 | 595 | } |
|---|
| | 596 | /* memgzip */ |
|---|
| | 597 | static 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 | } |
|---|
| 596 | 623 | static noit_boolean |
|---|
| 597 | 624 | _http_encode_chain(struct bchain *out, struct bchain *in, int opts) { |
|---|
| 598 | 625 | /* implement gzip and deflate! */ |
|---|
| 599 | 626 | 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; |
|---|
| 600 | 636 | } |
|---|
| 601 | 637 | else if(opts & NOIT_HTTP_DEFLATE) { |
|---|
| … | … | |
| 633 | 669 | |
|---|
| 634 | 670 | ilen = in->size; |
|---|
| 635 | | if(opts & NOIT_HTTP_GZIP) ilen = compressBound(ilen); |
|---|
| | 671 | if(opts & NOIT_HTTP_GZIP) ilen = deflateBound(NULL, ilen); |
|---|
| 636 | 672 | else if(opts & NOIT_HTTP_DEFLATE) ilen = compressBound(ilen); |
|---|
| 637 | 673 | out = bchain_alloc(hexlen + 4 + ilen); |
|---|
| r512f29e |
r26e5e98 |
|
| 377 | 377 | noit_http_response_status_set(ctx, 200, "OK"); |
|---|
| 378 | 378 | noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED); |
|---|
| | 379 | noit_http_response_option_set(ctx, NOIT_HTTP_GZIP); |
|---|
| 379 | 380 | /*noit_http_response_option_set(ctx, NOIT_HTTP_DEFLATE);*/ |
|---|
| 380 | 381 | noit_http_response_header_set(ctx, "Content-Type", "text/html"); |
|---|