| 445 |
char *token; |
char *token; |
| 446 |
const char *encoding; |
const char *encoding; |
| 447 |
|
|
| 448 |
/* only work on main request/no subrequests */ |
/* |
| 449 |
if (r->main != NULL) { |
* Only work on main request, not subrequests, |
| 450 |
ap_remove_output_filter(f); |
* that are not a 204 response with no content |
| 451 |
return ap_pass_brigade(f->next, bb); |
* and are not tagged with the no-gzip env variable |
| 452 |
} |
* and not a partial response to a Range request. |
| 453 |
|
*/ |
| 454 |
/* some browsers might have problems, so set no-gzip |
if ((r->main != NULL) || (r->status == HTTP_NO_CONTENT) || |
| 455 |
* (with browsermatch) for them |
apr_table_get(r->subprocess_env, "no-gzip") || |
| 456 |
*/ |
apr_table_get(r->headers_out, "Content-Range") |
| 457 |
if (apr_table_get(r->subprocess_env, "no-gzip")) { |
) { |
|
ap_remove_output_filter(f); |
|
|
return ap_pass_brigade(f->next, bb); |
|
|
} |
|
|
|
|
|
/* We can't operate on Content-Ranges */ |
|
|
if (apr_table_get(r->headers_out, "Content-Range") != NULL) { |
|
| 458 |
ap_remove_output_filter(f); |
ap_remove_output_filter(f); |
| 459 |
return ap_pass_brigade(f->next, bb); |
return ap_pass_brigade(f->next, bb); |
| 460 |
} |
} |
| 557 |
} |
} |
| 558 |
} |
} |
| 559 |
|
|
| 560 |
/* For a 304 or 204 response there is no entity included in |
/* At this point we have decided to filter the content, so change |
| 561 |
* the response and hence nothing to deflate. */ |
* important content metadata before sending any response out. |
| 562 |
if (r->status == HTTP_NOT_MODIFIED || r->status == HTTP_NO_CONTENT) { |
*/ |
| 563 |
|
|
| 564 |
|
/* If the entire Content-Encoding is "identity", we can replace it. */ |
| 565 |
|
if (!encoding || !strcasecmp(encoding, "identity")) { |
| 566 |
|
apr_table_setn(r->headers_out, "Content-Encoding", "gzip"); |
| 567 |
|
} |
| 568 |
|
else { |
| 569 |
|
apr_table_mergen(r->headers_out, "Content-Encoding", "gzip"); |
| 570 |
|
} |
| 571 |
|
/* Fix r->content_encoding if it was set before */ |
| 572 |
|
if (r->content_encoding) { |
| 573 |
|
r->content_encoding = apr_table_get(r->headers_out, |
| 574 |
|
"Content-Encoding"); |
| 575 |
|
} |
| 576 |
|
apr_table_unset(r->headers_out, "Content-Length"); |
| 577 |
|
apr_table_unset(r->headers_out, "Content-MD5"); |
| 578 |
|
deflate_check_etag(r, "gzip"); |
| 579 |
|
|
| 580 |
|
/* For a 304 response, only change the headers */ |
| 581 |
|
if (r->status == HTTP_NOT_MODIFIED) { |
| 582 |
ap_remove_output_filter(f); |
ap_remove_output_filter(f); |
| 583 |
return ap_pass_brigade(f->next, bb); |
return ap_pass_brigade(f->next, bb); |
| 584 |
} |
} |
| 585 |
|
|
|
/* We're cool with filtering this. */ |
|
| 586 |
ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx)); |
ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx)); |
| 587 |
ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc); |
ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc); |
| 588 |
ctx->buffer = apr_palloc(r->pool, c->bufferSize); |
ctx->buffer = apr_palloc(r->pool, c->bufferSize); |
| 618 |
f->c->bucket_alloc); |
f->c->bucket_alloc); |
| 619 |
APR_BRIGADE_INSERT_TAIL(ctx->bb, e); |
APR_BRIGADE_INSERT_TAIL(ctx->bb, e); |
| 620 |
|
|
|
/* If the entire Content-Encoding is "identity", we can replace it. */ |
|
|
if (!encoding || !strcasecmp(encoding, "identity")) { |
|
|
apr_table_setn(r->headers_out, "Content-Encoding", "gzip"); |
|
|
} |
|
|
else { |
|
|
apr_table_mergen(r->headers_out, "Content-Encoding", "gzip"); |
|
|
} |
|
|
/* Fix r->content_encoding if it was set before */ |
|
|
if (r->content_encoding) { |
|
|
r->content_encoding = apr_table_get(r->headers_out, |
|
|
"Content-Encoding"); |
|
|
} |
|
|
apr_table_unset(r->headers_out, "Content-Length"); |
|
|
apr_table_unset(r->headers_out, "Content-MD5"); |
|
|
deflate_check_etag(r, "gzip"); |
|
|
|
|
| 621 |
/* initialize deflate output buffer */ |
/* initialize deflate output buffer */ |
| 622 |
ctx->stream.next_out = ctx->buffer; |
ctx->stream.next_out = ctx->buffer; |
| 623 |
ctx->stream.avail_out = c->bufferSize; |
ctx->stream.avail_out = c->bufferSize; |
| 1047 |
|
|
| 1048 |
if (!ctx) { |
if (!ctx) { |
| 1049 |
|
|
| 1050 |
/* only work on main request/no subrequests */ |
/* |
| 1051 |
if (!ap_is_initial_req(r)) { |
* Only work on main request, not subrequests, |
| 1052 |
ap_remove_output_filter(f); |
* that are not a 204 response with no content |
| 1053 |
return ap_pass_brigade(f->next, bb); |
* and not a partial response to a Range request, |
| 1054 |
} |
* and only when Content-Encoding ends in gzip. |
| 1055 |
|
*/ |
| 1056 |
/* We can't operate on Content-Ranges */ |
if (!ap_is_initial_req(r) || (r->status == HTTP_NO_CONTENT) || |
| 1057 |
if (apr_table_get(r->headers_out, "Content-Range") != NULL) { |
(apr_table_get(r->headers_out, "Content-Range") != NULL) || |
| 1058 |
|
(check_gzip(r, r->headers_out, r->err_headers_out) == 0) |
| 1059 |
|
) { |
| 1060 |
ap_remove_output_filter(f); |
ap_remove_output_filter(f); |
| 1061 |
return ap_pass_brigade(f->next, bb); |
return ap_pass_brigade(f->next, bb); |
| 1062 |
} |
} |
| 1063 |
|
|
| 1064 |
/* |
/* |
| 1065 |
* Let's see what our current Content-Encoding is. |
* At this point we have decided to filter the content, so change |
| 1066 |
* Only inflate if gzipped. |
* important content metadata before sending any response out. |
| 1067 |
|
* Content-Encoding was already reset by the check_gzip() call. |
| 1068 |
*/ |
*/ |
| 1069 |
if (check_gzip(r, r->headers_out, r->err_headers_out) == 0) { |
apr_table_unset(r->headers_out, "Content-Length"); |
| 1070 |
ap_remove_output_filter(f); |
apr_table_unset(r->headers_out, "Content-MD5"); |
| 1071 |
return ap_pass_brigade(f->next, bb); |
deflate_check_etag(r, "gunzip"); |
|
} |
|
| 1072 |
|
|
| 1073 |
/* No need to inflate HEAD or 204/304 */ |
/* For a 304 response, only change the headers */ |
| 1074 |
if (APR_BUCKET_IS_EOS(APR_BRIGADE_FIRST(bb))) { |
if (r->status == HTTP_NOT_MODIFIED) { |
| 1075 |
ap_remove_output_filter(f); |
ap_remove_output_filter(f); |
| 1076 |
return ap_pass_brigade(f->next, bb); |
return ap_pass_brigade(f->next, bb); |
| 1077 |
} |
} |
| 1108 |
apr_pool_cleanup_register(r->pool, ctx, deflate_ctx_cleanup, |
apr_pool_cleanup_register(r->pool, ctx, deflate_ctx_cleanup, |
| 1109 |
apr_pool_cleanup_null); |
apr_pool_cleanup_null); |
| 1110 |
|
|
|
/* these are unlikely to be set anyway, but ... */ |
|
|
apr_table_unset(r->headers_out, "Content-Length"); |
|
|
apr_table_unset(r->headers_out, "Content-MD5"); |
|
|
deflate_check_etag(r, "gunzip"); |
|
|
|
|
| 1111 |
/* initialize inflate output buffer */ |
/* initialize inflate output buffer */ |
| 1112 |
ctx->stream.next_out = ctx->buffer; |
ctx->stream.next_out = ctx->buffer; |
| 1113 |
ctx->stream.avail_out = c->bufferSize; |
ctx->stream.avail_out = c->bufferSize; |