Skip to content

Commit

Permalink
fix(http): change proxy url generation (#7354)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Mar 20, 2024
1 parent 3c7b333 commit 318c316
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
11 changes: 4 additions & 7 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,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) => {
Expand Down
13 changes: 5 additions & 8 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,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 => {
Expand Down
11 changes: 4 additions & 7 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,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) => {
Expand Down

0 comments on commit 318c316

Please sign in to comment.