From 11e2b320056df5d197f19648bd57cd1b801d163b Mon Sep 17 00:00:00 2001 From: Tuan Pham <103537251+phantumcode@users.noreply.github.com> Date: Fri, 2 Feb 2024 20:57:26 +0000 Subject: [PATCH] chore(logging): update logging remote constraint ETag caching (#3494) * chore(logging): update logging remote constraint ETag caching * chore: add code comment --- .../DefaultRemoteLoggingConstraintsProvider.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteLoggingConstraintsProvider.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteLoggingConstraintsProvider.swift index 64c9863a96..3a6dac5bd0 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteLoggingConstraintsProvider.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteLoggingConstraintsProvider.swift @@ -58,7 +58,14 @@ public class DefaultRemoteLoggingConstraintsProvider: RemoteLoggingConstraintsPr let loggingConstraint = try JSONDecoder().decode(LoggingConstraints.self, from: data) loggingConstraintsLocalStore.setLocalLoggingConstraints(loggingConstraints: loggingConstraint) - if let etag = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "If-None-Match") { + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag + // the response header should only use the ETag header field in accordance with Http protocol spec + // but we need to also look at `If-None-Match` due to the initial/old lambda documentation recommending to + // `If-None-Match` to return the ETag + if let etag = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "ETag") { + loggingConstraintsLocalStore.setLocalLoggingConstraintsEtag(etag: etag) + } else if let etag = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "If-None-Match") { loggingConstraintsLocalStore.setLocalLoggingConstraintsEtag(etag: etag) } return loggingConstraint