@capacitor/ios
Advanced tools
Comparing version 5.5.1-nightly-20231025T150424.0 to 5.5.1
@@ -67,4 +67,48 @@ | ||
}; | ||
const convertBody = async (body) => { | ||
if (body instanceof FormData) { | ||
const convertBody = async (body, contentType) => { | ||
if (body instanceof ReadableStream) { | ||
const reader = body.getReader(); | ||
const chunks = []; | ||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) | ||
break; | ||
chunks.push(value); | ||
} | ||
const concatenated = new Uint8Array(chunks.reduce((acc, chunk) => acc + chunk.length, 0)); | ||
let position = 0; | ||
for (const chunk of chunks) { | ||
concatenated.set(chunk, position); | ||
position += chunk.length; | ||
} | ||
let data = new TextDecoder().decode(concatenated); | ||
let type; | ||
if (contentType === 'application/json') { | ||
try { | ||
data = JSON.parse(data); | ||
} | ||
catch (ignored) { | ||
// ignore | ||
} | ||
type = 'json'; | ||
} | ||
else if (contentType === 'multipart/form-data') { | ||
type = 'formData'; | ||
} | ||
else if (contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('image')) { | ||
type = 'image'; | ||
} | ||
else if (contentType === 'application/octet-stream') { | ||
type = 'binary'; | ||
} | ||
else { | ||
type = 'text'; | ||
} | ||
return { | ||
data, | ||
type, | ||
headers: { 'Content-Type': contentType || 'application/octet-stream' }, | ||
}; | ||
} | ||
else if (body instanceof FormData) { | ||
const formData = await convertFormData(body); | ||
@@ -435,5 +479,6 @@ const boundary = `${Date.now()}`; | ||
try { | ||
// intercept request & pass to the bridge | ||
const { body, method } = request; | ||
const { data: requestData, type, headers, } = await convertBody(body || undefined); | ||
const optionHeaders = Object.fromEntries(request.headers.entries()); | ||
const { data: requestData, type, headers, } = await convertBody((options === null || options === void 0 ? void 0 : options.body) || body || undefined, optionHeaders['Content-Type'] || optionHeaders['content-type']); | ||
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', { | ||
@@ -589,9 +634,19 @@ url: request.url, | ||
this.status = nativeResponse.status; | ||
const responseString = typeof nativeResponse.data !== 'string' | ||
? JSON.stringify(nativeResponse.data) | ||
: nativeResponse.data; | ||
if (this.responseType === '' || | ||
this.responseType === 'text') { | ||
this.response = | ||
typeof nativeResponse.data !== 'string' | ||
? JSON.stringify(nativeResponse.data) | ||
: nativeResponse.data; | ||
this.response = responseString; | ||
} | ||
else if (this.responseType === 'blob') { | ||
this.response = new Blob([responseString], { | ||
type: 'application/json', | ||
}); | ||
} | ||
else if (this.responseType === 'arraybuffer') { | ||
const encoder = new TextEncoder(); | ||
const uint8Array = encoder.encode(responseString); | ||
this.response = uint8Array.buffer; | ||
} | ||
else { | ||
@@ -662,3 +717,3 @@ this.response = nativeResponse.data; | ||
for (const key in this._headers) { | ||
if (key != 'Set-Cookie') { | ||
if (key.toLowerCase() !== 'set-cookie') { | ||
returnString += key + ': ' + this._headers[key] + '\r\n'; | ||
@@ -674,3 +729,8 @@ } | ||
} | ||
return this._headers[name]; | ||
for (const key in this._headers) { | ||
if (key.toLowerCase() === name.toLowerCase()) { | ||
return this._headers[key]; | ||
} | ||
} | ||
return null; | ||
}; | ||
@@ -677,0 +737,0 @@ Object.setPrototypeOf(xhr, prototype); |
{ | ||
"name": "@capacitor/ios", | ||
"version": "5.5.1-nightly-20231025T150424.0", | ||
"version": "5.5.1", | ||
"description": "Capacitor: Cross-platform apps with JavaScript and the web", | ||
@@ -28,3 +28,3 @@ "homepage": "https://capacitorjs.com", | ||
"peerDependencies": { | ||
"@capacitor/core": "^5.5.0-nightly-20231025T150424.0" | ||
"@capacitor/core": "^5.5.0" | ||
}, | ||
@@ -31,0 +31,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
337918
99
982
0