~ubuntu-branches/ubuntu/hardy/apache2/hardy-proposed

« back to all changes in this revision

Viewing changes to modules/filters/mod_deflate.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Fritsch
  • Date: 2008-01-17 20:27:56 UTC
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20080117202756-hv38rjknhwa2ilwi
Tags: upstream-2.2.8
ImportĀ upstreamĀ versionĀ 2.2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
293
293
    int (*libz_end_func)(z_streamp);
294
294
    unsigned char *validation_buffer;
295
295
    apr_size_t validation_buffer_length;
 
296
    int inflate_init;
296
297
} deflate_ctx;
297
298
 
298
299
/* Number of validation bytes (CRC and length) after the compressed data */
371
372
        ctx->libz_end_func(&ctx->stream);
372
373
    return APR_SUCCESS;
373
374
}
374
 
 
 
375
/* PR 39727: we're screwing up our clients if we leave a strong ETag
 
376
 * header while transforming content.  Henrik Nordstrom suggests
 
377
 * appending ";gzip".
 
378
 *
 
379
 * Pending a more thorough review of our Etag handling, let's just
 
380
 * implement his suggestion.  It fixes the bug, or at least turns it
 
381
 * from a showstopper to an inefficiency.  And it breaks nothing that
 
382
 * wasn't already broken.
 
383
 */
 
384
static void deflate_check_etag(request_rec *r, const char *transform)
 
385
{
 
386
    const char *etag = apr_table_get(r->headers_out, "ETag");
 
387
    if (etag && (((etag[0] != 'W') && (etag[0] !='w')) || (etag[1] != '/'))) {
 
388
        apr_table_set(r->headers_out, "ETag",
 
389
                      apr_pstrcat(r->pool, etag, "-", transform, NULL));
 
390
    }
 
391
}
375
392
static apr_status_t deflate_out_filter(ap_filter_t *f,
376
393
                                       apr_bucket_brigade *bb)
377
394
{
569
586
        }
570
587
        apr_table_unset(r->headers_out, "Content-Length");
571
588
        apr_table_unset(r->headers_out, "Content-MD5");
 
589
        deflate_check_etag(r, "gzip");
572
590
 
573
591
        /* initialize deflate output buffer */
574
592
        ctx->stream.next_out = ctx->buffer;
983
1001
{
984
1002
    int zlib_method;
985
1003
    int zlib_flags;
986
 
    int inflate_init = 1;
987
1004
    apr_bucket *e;
988
1005
    request_rec *r = f->r;
989
1006
    deflate_ctx *ctx = f->ctx;
1062
1079
        /* these are unlikely to be set anyway, but ... */
1063
1080
        apr_table_unset(r->headers_out, "Content-Length");
1064
1081
        apr_table_unset(r->headers_out, "Content-MD5");
 
1082
        deflate_check_etag(r, "gunzip");
1065
1083
 
1066
1084
        /* initialize inflate output buffer */
1067
1085
        ctx->stream.next_out = ctx->buffer;
1068
1086
        ctx->stream.avail_out = c->bufferSize;
1069
1087
 
1070
 
        inflate_init = 0;
 
1088
        ctx->inflate_init = 0;
1071
1089
    }
1072
1090
 
1073
1091
    while (!APR_BRIGADE_EMPTY(bb))
1172
1190
        apr_bucket_read(e, &data, &len, APR_BLOCK_READ);
1173
1191
 
1174
1192
        /* first bucket contains zlib header */
1175
 
        if (!inflate_init++) {
 
1193
        if (!ctx->inflate_init++) {
1176
1194
            if (len < 10) {
1177
1195
                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1178
1196
                              "Insufficient data for inflate");