From da39177fee8fc6f48248d82f5acf55ad709c03d0 Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Fri, 3 Jun 2016 15:35:30 -0600 Subject: [PATCH] TS-4506 Don't remove Expires/Last-Modifed on 304 response When generating a 304 page, we used to remove Expires and Last-Modified always. This change makes sure we never touch Expires, and only remove the Last-Modified header if there is an ETag in the response. This is per the specs in https://tools.ietf.org/html/rfc7232#page-18 --- proxy/http/HttpTransact.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc index 5ef04306d91..4864b48870a 100644 --- a/proxy/http/HttpTransact.cc +++ b/proxy/http/HttpTransact.cc @@ -8199,13 +8199,15 @@ HttpTransact::build_error_response(State *s, HTTPStatus status_code, const char if (has_ua_msie) s->hdr_info.client_response.value_set(MIME_FIELD_PROXY_CONNECTION, MIME_LEN_PROXY_CONNECTION, "close", 5); } - // Add a bunch of headers to make sure that caches between - // the Traffic Server and the client do not cache the error - // page. + // Make sure that caches between the Traffic Server and the client do not cache the error. + // ToDo: Not sure this matches expectation in RFC 7223. s->hdr_info.client_response.value_set(MIME_FIELD_CACHE_CONTROL, MIME_LEN_CACHE_CONTROL, "no-store", 8); - // Make sure there are no Expires and Last-Modified headers. - s->hdr_info.client_response.field_delete(MIME_FIELD_EXPIRES, MIME_LEN_EXPIRES); - s->hdr_info.client_response.field_delete(MIME_FIELD_LAST_MODIFIED, MIME_LEN_LAST_MODIFIED); + + // Remove the Last-Modified header, but only if there is an ETag header. See sec 4.1 in + // https://tools.ietf.org/html/rfc7232#page-18 + if (s->hdr_info.client_response.presence(MIME_PRESENCE_ETAG)) { + s->hdr_info.client_response.field_delete(MIME_FIELD_LAST_MODIFIED, MIME_LEN_LAST_MODIFIED); + } if ((status_code == HTTP_STATUS_TEMPORARY_REDIRECT || status_code == HTTP_STATUS_MOVED_TEMPORARILY || status_code == HTTP_STATUS_MOVED_PERMANENTLY) &&