Skip to content

Commit

Permalink
fix(android): make local urls use unpatched fetch (#6953)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Oct 4, 2023
1 parent 8f3f0dd commit e50e56c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
5 changes: 2 additions & 3 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,14 @@ var nativeBridge = (function (exports) {
// fetch patch
window.fetch = async (resource, options) => {
const request = new Request(resource, options);
if (!(request.url.startsWith('http:') ||
request.url.startsWith('https:'))) {
if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
return win.CapacitorWebFetch(resource, options);
}
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
console.time(tag);
try {
const { body, method } = request;
const { data: requestData, type, headers } = await convertBody(body || undefined);
const { data: requestData, type, headers, } = await convertBody(body || undefined);
const optionHeaders = Object.fromEntries(request.headers.entries());
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
url: request.url,
Expand Down
8 changes: 1 addition & 7 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,7 @@ const initBridge = (w: any): void => {
options?: RequestInit,
) => {
const request = new Request(resource, options);

if (
!(
request.url.startsWith('http:') ||
request.url.startsWith('https:')
)
) {
if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
return win.CapacitorWebFetch(resource, options);
}

Expand Down
5 changes: 2 additions & 3 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,14 @@ var nativeBridge = (function (exports) {
// fetch patch
window.fetch = async (resource, options) => {
const request = new Request(resource, options);
if (!(request.url.startsWith('http:') ||
request.url.startsWith('https:'))) {
if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
return win.CapacitorWebFetch(resource, options);
}
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
console.time(tag);
try {
const { body, method } = request;
const { data: requestData, type, headers } = await convertBody(body || undefined);
const { data: requestData, type, headers, } = await convertBody(body || undefined);
const optionHeaders = Object.fromEntries(request.headers.entries());
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
url: request.url,
Expand Down

0 comments on commit e50e56c

Please sign in to comment.