diff options
author | Yann Ylavic <ylavic@apache.org> | 2018-07-30 15:08:23 +0200 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2018-07-30 15:08:23 +0200 |
commit | f673148e9b8674aa6d5bd1efdd12679fc0099c79 (patch) | |
tree | e58ea171f44a4b345f5ccf154b189aa1c538509f /modules/http | |
parent | mod_proxy_http: follow up to r1836588: nonblocking read for 100-continue body. (diff) | |
download | apache2-f673148e9b8674aa6d5bd1efdd12679fc0099c79.tar.xz apache2-f673148e9b8674aa6d5bd1efdd12679fc0099c79.zip |
http: Enforce consistently no response body with both 204 and 304 statuses.
Provide AP_STATUS_IS_HEADER_ONLY() helper/macro to check for 204 or 304 and
use it where some special treatment is needed when no body is expected.
Some of those places handled 204 only.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1837056 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules/http')
-rw-r--r-- | modules/http/http_filters.c | 15 | ||||
-rw-r--r-- | modules/http/http_protocol.c | 25 |
2 files changed, 19 insertions, 21 deletions
diff --git a/modules/http/http_filters.c b/modules/http/http_filters.c index 2887136caf..0610154d68 100644 --- a/modules/http/http_filters.c +++ b/modules/http/http_filters.c @@ -1251,7 +1251,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, } else if (ctx->headers_sent) { /* Eat body if response must not have one. */ - if (r->header_only || r->status == HTTP_NO_CONTENT) { + if (r->header_only || AP_STATUS_IS_HEADER_ONLY(r->status)) { apr_brigade_cleanup(b); return APR_SUCCESS; } @@ -1356,12 +1356,15 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, basic_http_header_check(r, &protocol); ap_set_keepalive(r); - if (r->chunked) { - apr_table_mergen(r->headers_out, "Transfer-Encoding", "chunked"); + if (AP_STATUS_IS_HEADER_ONLY(r->status)) { + apr_table_unset(r->headers_out, "Transfer-Encoding"); apr_table_unset(r->headers_out, "Content-Length"); + r->content_type = r->content_encoding = NULL; + r->content_languages = NULL; + r->clength = r->chunked = 0; } - - if (r->status == HTTP_NO_CONTENT) { + else if (r->chunked) { + apr_table_mergen(r->headers_out, "Transfer-Encoding", "chunked"); apr_table_unset(r->headers_out, "Content-Length"); } @@ -1440,7 +1443,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, } ctx->headers_sent = 1; - if (r->header_only || r->status == HTTP_NO_CONTENT) { + if (r->header_only || AP_STATUS_IS_HEADER_ONLY(r->status)) { apr_brigade_cleanup(b); goto out; } diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 97182dc3d7..928596c29b 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -254,9 +254,8 @@ AP_DECLARE(int) ap_set_keepalive(request_rec *r) */ if ((r->connection->keepalive != AP_CONN_CLOSE) && !r->expecting_100 - && ((r->status == HTTP_NOT_MODIFIED) - || (r->status == HTTP_NO_CONTENT) - || r->header_only + && (r->header_only + || AP_STATUS_IS_HEADER_ONLY(r->status) || apr_table_get(r->headers_out, "Content-Length") || ap_find_last_token(r->pool, apr_table_get(r->headers_out, @@ -1239,26 +1238,22 @@ AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error) ap_run_insert_error_filter(r); - /* - * It's possible that the Location field might be in r->err_headers_out - * instead of r->headers_out; use the latter if possible, else the - * former. - */ - if (location == NULL) { - location = apr_table_get(r->err_headers_out, "Location"); - } /* We need to special-case the handling of 204 and 304 responses, * since they have specific HTTP requirements and do not include a * message body. Note that being assbackwards here is not an option. */ - if (status == HTTP_NOT_MODIFIED) { + if (AP_STATUS_IS_HEADER_ONLY(status)) { ap_finalize_request_protocol(r); return; } - if (status == HTTP_NO_CONTENT) { - ap_finalize_request_protocol(r); - return; + /* + * It's possible that the Location field might be in r->err_headers_out + * instead of r->headers_out; use the latter if possible, else the + * former. + */ + if (location == NULL) { + location = apr_table_get(r->err_headers_out, "Location"); } if (!r->assbackwards) { |