From 30a32f467fb4c5cc6c4e1b98e55f97a8c14befa5 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Wed, 20 Mar 2024 18:55:59 +0100 Subject: [PATCH] fix(http): change proxy url generation --- android/capacitor/src/main/assets/native-bridge.js | 11 ++++------- core/native-bridge.ts | 13 +++++-------- ios/Capacitor/Capacitor/assets/native-bridge.js | 11 ++++------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/android/capacitor/src/main/assets/native-bridge.js b/android/capacitor/src/main/assets/native-bridge.js index 2db2545b32..f0f70e6b33 100644 --- a/android/capacitor/src/main/assets/native-bridge.js +++ b/android/capacitor/src/main/assets/native-bridge.js @@ -145,13 +145,10 @@ var nativeBridge = (function (exports) { const proxyUrl = new URL(url); const bridgeUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : ''); const isHttps = proxyUrl.protocol === 'https:'; - const originalHost = encodeURIComponent(proxyUrl.host); - const originalPathname = proxyUrl.pathname; - proxyUrl.protocol = bridgeUrl.protocol; - proxyUrl.hostname = bridgeUrl.hostname; - proxyUrl.port = bridgeUrl.port; - proxyUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${originalHost}${originalPathname}`; - return proxyUrl.toString(); + bridgeUrl.search = proxyUrl.search; + bridgeUrl.hash = proxyUrl.hash; + bridgeUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${encodeURIComponent(proxyUrl.host)}${proxyUrl.pathname}`; + return bridgeUrl.toString(); }; const initBridge = (w) => { const getPlatformId = (win) => { diff --git a/core/native-bridge.ts b/core/native-bridge.ts index 48e9e5ef8e..9f3653c7a3 100644 --- a/core/native-bridge.ts +++ b/core/native-bridge.ts @@ -135,15 +135,12 @@ const createProxyUrl = (url: string, win: WindowCapacitor): string => { const proxyUrl = new URL(url); const bridgeUrl = new URL(win.Capacitor?.getServerUrl() ?? ''); const isHttps = proxyUrl.protocol === 'https:'; - const originalHost = encodeURIComponent(proxyUrl.host); - const originalPathname = proxyUrl.pathname; - proxyUrl.protocol = bridgeUrl.protocol; - proxyUrl.hostname = bridgeUrl.hostname; - proxyUrl.port = bridgeUrl.port; - proxyUrl.pathname = `${ + bridgeUrl.search = proxyUrl.search; + bridgeUrl.hash = proxyUrl.hash; + bridgeUrl.pathname = `${ isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR - }/${originalHost}${originalPathname}`; - return proxyUrl.toString(); + }/${encodeURIComponent(proxyUrl.host)}${proxyUrl.pathname}`; + return bridgeUrl.toString(); }; const initBridge = (w: any): void => { diff --git a/ios/Capacitor/Capacitor/assets/native-bridge.js b/ios/Capacitor/Capacitor/assets/native-bridge.js index 2db2545b32..f0f70e6b33 100644 --- a/ios/Capacitor/Capacitor/assets/native-bridge.js +++ b/ios/Capacitor/Capacitor/assets/native-bridge.js @@ -145,13 +145,10 @@ var nativeBridge = (function (exports) { const proxyUrl = new URL(url); const bridgeUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : ''); const isHttps = proxyUrl.protocol === 'https:'; - const originalHost = encodeURIComponent(proxyUrl.host); - const originalPathname = proxyUrl.pathname; - proxyUrl.protocol = bridgeUrl.protocol; - proxyUrl.hostname = bridgeUrl.hostname; - proxyUrl.port = bridgeUrl.port; - proxyUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${originalHost}${originalPathname}`; - return proxyUrl.toString(); + bridgeUrl.search = proxyUrl.search; + bridgeUrl.hash = proxyUrl.hash; + bridgeUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${encodeURIComponent(proxyUrl.host)}${proxyUrl.pathname}`; + return bridgeUrl.toString(); }; const initBridge = (w) => { const getPlatformId = (win) => {