From 687b6b1780506c17fb73ed1d9cbf50c1d1e40ef1 Mon Sep 17 00:00:00 2001 From: Chace Daniels Date: Thu, 21 Sep 2023 12:34:40 -0500 Subject: [PATCH] fix(http): return xhr response headers case insensitive --- android/capacitor/src/main/assets/native-bridge.js | 11 ++++++++--- core/native-bridge.ts | 9 +++++++-- ios/Capacitor/Capacitor/assets/native-bridge.js | 11 ++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/android/capacitor/src/main/assets/native-bridge.js b/android/capacitor/src/main/assets/native-bridge.js index 1f72392a6..a1ffa219f 100644 --- a/android/capacitor/src/main/assets/native-bridge.js +++ b/android/capacitor/src/main/assets/native-bridge.js @@ -595,7 +595,7 @@ var nativeBridge = (function (exports) { } else if (this.responseType === 'blob') { this.response = new Blob([responseString], { - type: "application/json", + type: 'application/json', }); } else if (this.responseType === 'arraybuffer') { @@ -668,7 +668,7 @@ var nativeBridge = (function (exports) { } let returnString = ''; for (const key in this._headers) { - if (key != 'Set-Cookie') { + if (key.toLowerCase() !== 'set-cookie') { returnString += key + ': ' + this._headers[key] + '\r\n'; } } @@ -679,7 +679,12 @@ var nativeBridge = (function (exports) { if (isRelativeURL(this._url)) { return win.CapacitorWebXMLHttpRequest.getResponseHeader.call(this, name); } - return this._headers[name]; + for (const key in this._headers) { + if (key.toLowerCase() === name.toLowerCase()) { + return this._headers[key]; + } + } + return null; }; Object.setPrototypeOf(xhr, prototype); return xhr; diff --git a/core/native-bridge.ts b/core/native-bridge.ts index aad89fa4a..71e006a42 100644 --- a/core/native-bridge.ts +++ b/core/native-bridge.ts @@ -787,7 +787,7 @@ const initBridge = (w: any): void => { let returnString = ''; for (const key in this._headers) { - if (key != 'Set-Cookie') { + if (key.toLowerCase() !== 'set-cookie') { returnString += key + ': ' + this._headers[key] + '\r\n'; } } @@ -802,7 +802,12 @@ const initBridge = (w: any): void => { name, ); } - return this._headers[name]; + for (const key in this._headers) { + if (key.toLowerCase() === name.toLowerCase()) { + return this._headers[key]; + } + } + return null; }; Object.setPrototypeOf(xhr, prototype); diff --git a/ios/Capacitor/Capacitor/assets/native-bridge.js b/ios/Capacitor/Capacitor/assets/native-bridge.js index 1f72392a6..a1ffa219f 100644 --- a/ios/Capacitor/Capacitor/assets/native-bridge.js +++ b/ios/Capacitor/Capacitor/assets/native-bridge.js @@ -595,7 +595,7 @@ var nativeBridge = (function (exports) { } else if (this.responseType === 'blob') { this.response = new Blob([responseString], { - type: "application/json", + type: 'application/json', }); } else if (this.responseType === 'arraybuffer') { @@ -668,7 +668,7 @@ var nativeBridge = (function (exports) { } let returnString = ''; for (const key in this._headers) { - if (key != 'Set-Cookie') { + if (key.toLowerCase() !== 'set-cookie') { returnString += key + ': ' + this._headers[key] + '\r\n'; } } @@ -679,7 +679,12 @@ var nativeBridge = (function (exports) { if (isRelativeURL(this._url)) { return win.CapacitorWebXMLHttpRequest.getResponseHeader.call(this, name); } - return this._headers[name]; + for (const key in this._headers) { + if (key.toLowerCase() === name.toLowerCase()) { + return this._headers[key]; + } + } + return null; }; Object.setPrototypeOf(xhr, prototype); return xhr;