Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,22 +423,21 @@ var nativeBridge = (function (exports) {
if (doPatchHttp) {
// fetch patch
window.fetch = async (resource, options) => {
if (!(resource.toString().startsWith('http:') ||
resource.toString().startsWith('https:'))) {
const request = new Request(resource, options);
if (!(request.url.startsWith('http:') ||
request.url.startsWith('https:'))) {
return win.CapacitorWebFetch(resource, options);
}
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
console.time(tag);
try {
// intercept request & pass to the bridge
const { data: requestData, type, headers, } = await convertBody((options === null || options === void 0 ? void 0 : options.body) || undefined);
let optionHeaders = options === null || options === void 0 ? void 0 : options.headers;
if ((options === null || options === void 0 ? void 0 : options.headers) instanceof Headers) {
optionHeaders = Object.fromEntries(options.headers.entries());
}
const { body, method } = request;
const { data: requestData, type, headers, } = await convertBody(body || undefined);
const optionHeaders = Object.fromEntries(request.headers.entries());
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
url: resource,
method: (options === null || options === void 0 ? void 0 : options.method) ? options.method : undefined,
url: request.url,
method: method,
data: requestData,
dataType: type,
headers: Object.assign(Object.assign({}, headers), optionHeaders),
Expand Down
20 changes: 9 additions & 11 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,12 @@ const initBridge = (w: any): void => {
resource: RequestInfo | URL,
options?: RequestInit,
) => {
const request = new Request(resource, options);

if (
!(
resource.toString().startsWith('http:') ||
resource.toString().startsWith('https:')
request.url.startsWith('http:') ||
request.url.startsWith('https:')
)
) {
return win.CapacitorWebFetch(resource, options);
Expand All @@ -484,23 +486,19 @@ const initBridge = (w: any): void => {
console.time(tag);
try {
// intercept request & pass to the bridge
const { body, method } = request;
const {
data: requestData,
type,
headers,
} = await convertBody(options?.body || undefined);
let optionHeaders = options?.headers;
if (options?.headers instanceof Headers) {
optionHeaders = Object.fromEntries(
(options.headers as any).entries(),
);
}
} = await convertBody(body || undefined);
const optionHeaders = Object.fromEntries(request.headers.entries());
const nativeResponse: HttpResponse = await cap.nativePromise(
'CapacitorHttp',
'request',
{
url: resource,
method: options?.method ? options.method : undefined,
url: request.url,
method: method,
data: requestData,
dataType: type,
headers: {
Expand Down
17 changes: 8 additions & 9 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,22 +423,21 @@ var nativeBridge = (function (exports) {
if (doPatchHttp) {
// fetch patch
window.fetch = async (resource, options) => {
if (!(resource.toString().startsWith('http:') ||
resource.toString().startsWith('https:'))) {
const request = new Request(resource, options);
if (!(request.url.startsWith('http:') ||
request.url.startsWith('https:'))) {
return win.CapacitorWebFetch(resource, options);
}
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
console.time(tag);
try {
// intercept request & pass to the bridge
const { data: requestData, type, headers, } = await convertBody((options === null || options === void 0 ? void 0 : options.body) || undefined);
let optionHeaders = options === null || options === void 0 ? void 0 : options.headers;
if ((options === null || options === void 0 ? void 0 : options.headers) instanceof Headers) {
optionHeaders = Object.fromEntries(options.headers.entries());
}
const { body, method } = request;
const { data: requestData, type, headers, } = await convertBody(body || undefined);
const optionHeaders = Object.fromEntries(request.headers.entries());
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
url: resource,
method: (options === null || options === void 0 ? void 0 : options.method) ? options.method : undefined,
url: request.url,
method: method,
data: requestData,
dataType: type,
headers: Object.assign(Object.assign({}, headers), optionHeaders),
Expand Down