Skip to content

Commit

Permalink
fix: handle fetch headers that are Headers objects (#6320)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Feb 22, 2023
1 parent a3f875c commit cb00e49
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
14 changes: 9 additions & 5 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*! Capacitor: https://capacitorjs.com/ - MIT License */
/* Generated File. Do not edit. */

const nativeBridge = (function (exports) {
var nativeBridge = (function (exports) {
'use strict';

var ExceptionCode;
Expand Down Expand Up @@ -374,13 +374,15 @@ const nativeBridge = (function (exports) {
console.time(tag);
try {
// intercept request & pass to the bridge
let headers = options === null || options === void 0 ? void 0 : options.headers;
if ((options === null || options === void 0 ? void 0 : options.headers) instanceof Headers) {
headers = Object.fromEntries(options.headers.entries());
}
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
url: resource,
method: (options === null || options === void 0 ? void 0 : options.method) ? options.method : undefined,
data: (options === null || options === void 0 ? void 0 : options.body) ? options.body : undefined,
headers: (options === null || options === void 0 ? void 0 : options.headers)
? options.headers
: undefined,
headers: headers,
});
const data = typeof nativeResponse.data === 'string'
? nativeResponse.data
Expand Down Expand Up @@ -508,7 +510,9 @@ const nativeBridge = (function (exports) {
url: this._url,
method: this._method,
data: body !== null ? body : undefined,
headers: this._headers != null && Object.keys(this._headers).length > 0 ? this._headers : undefined,
headers: this._headers != null && Object.keys(this._headers).length > 0
? this._headers
: undefined,
})
.then((nativeResponse) => {
// intercept & parse response before returning
Expand Down
6 changes: 5 additions & 1 deletion core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,18 @@ const initBridge = (w: any): void => {
console.time(tag);
try {
// intercept request & pass to the bridge
let headers = options?.headers;
if (options?.headers instanceof Headers) {
headers = Object.fromEntries((options.headers as any).entries());
}
const nativeResponse: HttpResponse = await cap.nativePromise(
'CapacitorHttp',
'request',
{
url: resource,
method: options?.method ? options.method : undefined,
data: options?.body ? options.body : undefined,
headers: options?.headers ? options.headers : undefined,
headers: headers,
},
);

Expand Down
14 changes: 9 additions & 5 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*! Capacitor: https://capacitorjs.com/ - MIT License */
/* Generated File. Do not edit. */

const nativeBridge = (function (exports) {
var nativeBridge = (function (exports) {
'use strict';

var ExceptionCode;
Expand Down Expand Up @@ -374,13 +374,15 @@ const nativeBridge = (function (exports) {
console.time(tag);
try {
// intercept request & pass to the bridge
let headers = options === null || options === void 0 ? void 0 : options.headers;
if ((options === null || options === void 0 ? void 0 : options.headers) instanceof Headers) {
headers = Object.fromEntries(options.headers.entries());
}
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
url: resource,
method: (options === null || options === void 0 ? void 0 : options.method) ? options.method : undefined,
data: (options === null || options === void 0 ? void 0 : options.body) ? options.body : undefined,
headers: (options === null || options === void 0 ? void 0 : options.headers)
? options.headers
: undefined,
headers: headers,
});
const data = typeof nativeResponse.data === 'string'
? nativeResponse.data
Expand Down Expand Up @@ -508,7 +510,9 @@ const nativeBridge = (function (exports) {
url: this._url,
method: this._method,
data: body !== null ? body : undefined,
headers: this._headers != null && Object.keys(this._headers).length > 0 ? this._headers : undefined,
headers: this._headers != null && Object.keys(this._headers).length > 0
? this._headers
: undefined,
})
.then((nativeResponse) => {
// intercept & parse response before returning
Expand Down

0 comments on commit cb00e49

Please sign in to comment.