From 662179e36e70c501fa20229450aca384f727feaa Mon Sep 17 00:00:00 2001 From: Lajos Szoke <63732287+laliconfigcat@users.noreply.github.com> Date: Wed, 27 Dec 2023 11:26:49 +0100 Subject: [PATCH] Send etag as query param (#91) * sendetagasqueryparam * comments * v9.2.0 --- package-lock.json | 4 ++-- package.json | 2 +- src/ConfigFetcher.ts | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index deb4253..cebad0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "configcat-js", - "version": "9.1.0", + "version": "9.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "configcat-js", - "version": "9.1.0", + "version": "9.2.0", "license": "MIT", "dependencies": { "configcat-common": "^9.0.0", diff --git a/package.json b/package.json index 311db1e..4a89a32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "configcat-js", - "version": "9.1.0", + "version": "9.2.0", "description": "ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/ConfigFetcher.ts b/src/ConfigFetcher.ts index e4a1d3e..31e286a 100644 --- a/src/ConfigFetcher.ts +++ b/src/ConfigFetcher.ts @@ -35,10 +35,16 @@ export class HttpConfigFetcher implements IConfigFetcher { httpRequest.onabort = () => reject(new FetchError("abort")); httpRequest.onerror = () => reject(new FetchError("failure")); - httpRequest.open("GET", options.getUrl(), true); + let url = options.getUrl(); + if (lastEtag) { + // We are sending the etag as a query parameter so if the browser doesn't automatically adds the If-None-Match header, we can transorm this query param to the header in our CDN provider. + url += '&ccetag=' + lastEtag; + } + httpRequest.open("GET", url, true); httpRequest.timeout = options.requestTimeoutMs; // NOTE: It's intentional that we don't specify the If-None-Match header. // The browser automatically handles it, adding it manually would cause an unnecessary CORS OPTIONS request. + // In case the browser doesn't handle it, we are transforming the ccetag query parameter to the If-None-Match header in our CDN provider. httpRequest.send(null); } catch (err) {