Skip to content

Commit a37fe58

Browse files
authored
Revert "Do not invalidate cached resources upon error responses to unsafe methods (#7864)" (#7954)
This reverts commit c75c797. This change introduces a failure in the esi AuTest. I'll revert this now to free up CI and circle back around on the patch later.
1 parent f3fb74e commit a37fe58

File tree

8 files changed

+7
-904
lines changed

8 files changed

+7
-904
lines changed

proxy/hdrs/HTTP.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ class HTTPHdr : public MIMEHdr
508508
void version_set(HTTPVersion version);
509509

510510
const char *method_get(int *length);
511-
int method_get_wksidx() const;
511+
int method_get_wksidx();
512512
void method_set(const char *value, int length);
513513

514514
URL *url_create(URL *url);
@@ -957,7 +957,7 @@ HTTPHdr::method_get(int *length)
957957
}
958958

959959
inline int
960-
HTTPHdr::method_get_wksidx() const
960+
HTTPHdr::method_get_wksidx()
961961
{
962962
ink_assert(valid());
963963
ink_assert(m_http->m_polarity == HTTP_TYPE_REQUEST);

proxy/http/HttpTransact.cc

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,14 +2085,6 @@ HttpTransact::OSDNSLookup(State *s)
20852085
} else if (s->cache_lookup_result == CACHE_LOOKUP_MISS || s->cache_info.action == CACHE_DO_NO_ACTION) {
20862086
TRANSACT_RETURN(SM_ACTION_API_OS_DNS, HandleCacheOpenReadMiss);
20872087
// DNS lookup is done if the lookup failed and need to call Handle Cache Open Read Miss
2088-
} else if (s->cache_info.action == CACHE_PREPARE_TO_WRITE && s->http_config_param->cache_post_method == 1 &&
2089-
s->method == HTTP_WKSIDX_POST) {
2090-
// By virtue of being here, we are intending to forward the request on
2091-
// to the server. If we marked this as CACHE_PREPARE_TO_WRITE and this
2092-
// is a POST request whose response we intend to write, then we have to
2093-
// proceed from here by calling the function that handles this as a
2094-
// miss.
2095-
TRANSACT_RETURN(SM_ACTION_API_OS_DNS, HandleCacheOpenReadMiss);
20962088
} else {
20972089
build_error_response(s, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Invalid Cache Lookup result", "default");
20982090
Log::error("HTTP: Invalid CACHE LOOKUP RESULT : %d", s->cache_lookup_result);
@@ -3101,8 +3093,7 @@ HttpTransact::build_response_from_cache(State *s, HTTPWarningCode warning_code)
31013093
// fall through
31023094
default:
31033095
SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_HIT_SERVED);
3104-
if (s->method == HTTP_WKSIDX_GET || (s->http_config_param->cache_post_method == 1 && s->method == HTTP_WKSIDX_POST) ||
3105-
s->api_resp_cacheable == true) {
3096+
if (s->method == HTTP_WKSIDX_GET || s->api_resp_cacheable == true) {
31063097
// send back the full document to the client.
31073098
TxnDebug("http_trans", "[build_response_from_cache] Match! Serving full document.");
31083099
s->cache_info.action = CACHE_DO_SERVE;
@@ -3332,7 +3323,7 @@ HttpTransact::HandleCacheOpenReadMiss(State *s)
33323323
if (GET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP) == ' ') {
33333324
SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_MISS_NOT_CACHED);
33343325
}
3335-
// We do a cache lookup for some non-GET requests as well.
3326+
// We do a cache lookup for DELETE and PUT requests as well.
33363327
// We must, however, not cache the responses to these requests.
33373328
if (does_method_require_cache_copy_deletion(s->http_config_param, s->method) && s->api_req_cacheable == false) {
33383329
s->cache_info.action = CACHE_DO_NO_ACTION;
@@ -4484,11 +4475,10 @@ HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
44844475
// cacheability of server response, and request method
44854476
// precondition: s->cache_info.action is one of the following
44864477
// CACHE_DO_UPDATE, CACHE_DO_WRITE, or CACHE_DO_DELETE
4487-
int const server_request_method = s->hdr_info.server_request.method_get_wksidx();
44884478
if (s->api_server_response_no_store) {
44894479
s->cache_info.action = CACHE_DO_NO_ACTION;
44904480
} else if (s->api_server_response_ignore && server_response_code == HTTP_STATUS_OK &&
4491-
server_request_method == HTTP_WKSIDX_HEAD) {
4481+
s->hdr_info.server_request.method_get_wksidx() == HTTP_WKSIDX_HEAD) {
44924482
s->api_server_response_ignore = false;
44934483
ink_assert(s->cache_info.object_read);
44944484
base_response = s->cache_info.object_read->response_get();
@@ -4505,21 +4495,7 @@ HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
45054495
} else if (s->www_auth_content == CACHE_AUTH_STALE && server_response_code == HTTP_STATUS_UNAUTHORIZED) {
45064496
s->cache_info.action = CACHE_DO_NO_ACTION;
45074497
} else if (!cacheable) {
4508-
if (HttpTransactHeaders::is_status_an_error_response(server_response_code) &&
4509-
!HttpTransactHeaders::is_method_safe(server_request_method)) {
4510-
// Only delete the cache entry if the response is successful. For
4511-
// unsuccessful responses, the transaction doesn't invalidate our
4512-
// entry. This behavior complies with RFC 7234, section 4.4 which
4513-
// stipulates that the entry only need be invalidated for non-error
4514-
// responses:
4515-
//
4516-
// A cache MUST invalidate the effective request URI (Section 5.5 of
4517-
// [RFC7230]) when it receives a non-error response to a request
4518-
// with a method whose safety is unknown.
4519-
s->cache_info.action = CACHE_DO_NO_ACTION;
4520-
} else {
4521-
s->cache_info.action = CACHE_DO_DELETE;
4522-
}
4498+
s->cache_info.action = CACHE_DO_DELETE;
45234499
} else if (s->method == HTTP_WKSIDX_HEAD) {
45244500
s->cache_info.action = CACHE_DO_DELETE;
45254501
} else {
@@ -4537,19 +4513,7 @@ HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
45374513
}
45384514

45394515
} else if (s->cache_info.action == CACHE_DO_DELETE) {
4540-
if (!cacheable && HttpTransactHeaders::is_status_an_error_response(server_response_code) &&
4541-
!HttpTransactHeaders::is_method_safe(server_request_method)) {
4542-
// Only delete the cache entry if the response is successful. For
4543-
// unsuccessful responses, the transaction doesn't invalidate our
4544-
// entry. This behavior complies with RFC 7234, section 4.4 which
4545-
// stipulates that the entry only need be invalidated for non-error
4546-
// responses:
4547-
//
4548-
// A cache MUST invalidate the effective request URI (Section 5.5 of
4549-
// [RFC7230]) when it receives a non-error response to a request
4550-
// with a method whose safety is unknown.
4551-
s->cache_info.action = CACHE_DO_NO_ACTION;
4552-
}
4516+
// do nothing
45534517

45544518
} else {
45554519
ink_assert(!("cache action inconsistent with current state"));
@@ -5956,18 +5920,6 @@ HttpTransact::is_cache_response_returnable(State *s)
59565920
SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_MISS_METHOD);
59575921
return false;
59585922
}
5959-
// We may be caching responses to methods other than GET, such as POST. Make
5960-
// sure that our cached resource has a method that matches the incoming
5961-
// requests's method. If not, then we cannot reply with the cached resource.
5962-
// That is, we cannot reply to an incoming GET request with a response to a
5963-
// previous POST request.
5964-
int const client_request_method = s->hdr_info.client_request.method_get_wksidx();
5965-
int const cached_request_method = s->cache_info.object_read->request_get()->method_get_wksidx();
5966-
if (client_request_method != cached_request_method) {
5967-
SET_VIA_STRING(VIA_CACHE_RESULT, VIA_IN_CACHE_NOT_ACCEPTABLE);
5968-
SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_MISS_METHOD);
5969-
return false;
5970-
}
59715923
// If cookies in response and no TTL set, we do not cache the doc
59725924
if ((s->cache_control.ttl_in_cache <= 0) &&
59735925
do_cookies_prevent_caching(static_cast<int>(s->txn_conf->cache_responses_to_cookies), &s->hdr_info.client_request,

proxy/http/HttpTransactHeaders.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,9 @@ HttpTransactHeaders::is_this_method_supported(int the_scheme, int the_method)
8787
bool
8888
HttpTransactHeaders::is_method_safe(int method)
8989
{
90-
// See RFC 7231, section 4.2.1.
9190
return (method == HTTP_WKSIDX_GET || method == HTTP_WKSIDX_OPTIONS || method == HTTP_WKSIDX_HEAD || method == HTTP_WKSIDX_TRACE);
9291
}
9392

94-
bool
95-
HttpTransactHeaders::is_status_an_error_response(HTTPStatus response_code)
96-
{
97-
auto const comparable_response_code = static_cast<unsigned int>(response_code);
98-
return (comparable_response_code >= 400) && (comparable_response_code <= 599);
99-
}
100-
10193
bool
10294
HttpTransactHeaders::is_method_idempotent(int method)
10395
{

proxy/http/HttpTransactHeaders.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class HttpTransactHeaders
5656
static bool downgrade_request(bool *origin_server_keep_alive, HTTPHdr *outgoing_request);
5757
static bool is_method_safe(int method);
5858
static bool is_method_idempotent(int method);
59-
static bool is_status_an_error_response(HTTPStatus response_code);
6059

6160
static void generate_and_set_squid_codes(HTTPHdr *header, char *via_string, HttpTransact::SquidLogInfo *squid_codes);
6261

tests/gold_tests/cache/cache-request-method.test.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)