Skip to content

Commit

Permalink
fix(http): keep original URL properties on proxy (#7338)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Mar 13, 2024
1 parent 03febfa commit 9ef8b1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ var nativeBridge = (function (exports) {
var _a, _b;
if (isRelativeOrProxyUrl(url))
return url;
let proxyUrl = new URL(url);
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 = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : '');
proxyUrl.protocol = bridgeUrl.protocol;
proxyUrl.host = bridgeUrl.host;
proxyUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${originalHost}${originalPathname}`;
return proxyUrl.toString();
};
Expand Down
7 changes: 4 additions & 3 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ const isRelativeOrProxyUrl = (url: string | undefined): boolean =>
const createProxyUrl = (url: string, win: WindowCapacitor): string => {
if (isRelativeOrProxyUrl(url)) return url;

let proxyUrl = new URL(url);
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 = new URL(win.Capacitor?.getServerUrl() ?? '');

proxyUrl.protocol = bridgeUrl.protocol;
proxyUrl.host = bridgeUrl.host;
proxyUrl.pathname = `${
isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR
}/${originalHost}${originalPathname}`;
Expand Down
6 changes: 4 additions & 2 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ var nativeBridge = (function (exports) {
var _a, _b;
if (isRelativeOrProxyUrl(url))
return url;
let proxyUrl = new URL(url);
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 = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : '');
proxyUrl.protocol = bridgeUrl.protocol;
proxyUrl.host = bridgeUrl.host;
proxyUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${originalHost}${originalPathname}`;
return proxyUrl.toString();
};
Expand Down

0 comments on commit 9ef8b1d

Please sign in to comment.