@capacitor/ios 5.7.6 → 5.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -91,7 +91,9 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol {
|
|
|
91
91
|
public static let capacitorSite = "https://capacitorjs.com/"
|
|
92
92
|
public static let fileStartIdentifier = "/_capacitor_file_"
|
|
93
93
|
public static let httpInterceptorStartIdentifier = "/_capacitor_http_interceptor_"
|
|
94
|
+
@available(*, deprecated, message: "`httpsInterceptorStartIdentifier` is no longer required. All proxied requests are handled via `httpInterceptorStartIdentifier` instead")
|
|
94
95
|
public static let httpsInterceptorStartIdentifier = "/_capacitor_https_interceptor_"
|
|
96
|
+
public static let httpInterceptorUrlParam = "u"
|
|
95
97
|
public static let defaultScheme = "capacitor"
|
|
96
98
|
|
|
97
99
|
var webViewAssetHandler: WebViewAssetHandler
|
|
@@ -35,11 +35,6 @@ internal class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
35
35
|
return
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
if url.path.starts(with: CapacitorBridge.httpsInterceptorStartIdentifier) {
|
|
39
|
-
handleCapacitorHttpRequest(urlSchemeTask, localUrl, true)
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
38
|
if stringToLoad.starts(with: CapacitorBridge.fileStartIdentifier) {
|
|
44
39
|
startPath = stringToLoad.replacingOccurrences(of: CapacitorBridge.fileStartIdentifier, with: "")
|
|
45
40
|
} else {
|
|
@@ -138,21 +133,13 @@ internal class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
138
133
|
func handleCapacitorHttpRequest(_ urlSchemeTask: WKURLSchemeTask, _ localUrl: URL, _ isHttpsRequest: Bool) {
|
|
139
134
|
var urlRequest = urlSchemeTask.request
|
|
140
135
|
guard let url = urlRequest.url else { return }
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
targetUrl = targetUrl.replacingCharacters(in: range, with: isHttpsRequest ? "https" : "http")
|
|
136
|
+
|
|
137
|
+
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
|
|
138
|
+
if let targetUrl = urlComponents?.queryItems?.first(where: { $0.name == CapacitorBridge.httpInterceptorUrlParam })?.value,
|
|
139
|
+
!targetUrl.isEmpty {
|
|
140
|
+
urlRequest.url = URL(string: targetUrl)
|
|
147
141
|
}
|
|
148
142
|
|
|
149
|
-
// Only replace first occurrence of the hostname
|
|
150
|
-
if let range = targetUrl.range(of: (localUrl.host ?? InstanceDescriptorDefaults.hostname) + "/") {
|
|
151
|
-
targetUrl = targetUrl.replacingCharacters(in: range, with: "")
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
urlRequest.url = URL(string: targetUrl.removingPercentEncoding ?? targetUrl)
|
|
155
|
-
|
|
156
143
|
let urlSession = URLSession.shared
|
|
157
144
|
let task = urlSession.dataTask(with: urlRequest) { (data, response, error) in
|
|
158
145
|
DispatchQueue.main.async {
|
|
@@ -65,22 +65,29 @@ var nativeBridge = (function (exports) {
|
|
|
65
65
|
return newFormData;
|
|
66
66
|
};
|
|
67
67
|
const convertBody = async (body, contentType) => {
|
|
68
|
-
if (body instanceof ReadableStream) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
if (body instanceof ReadableStream || body instanceof Uint8Array) {
|
|
69
|
+
let encodedData;
|
|
70
|
+
if (body instanceof ReadableStream) {
|
|
71
|
+
const reader = body.getReader();
|
|
72
|
+
const chunks = [];
|
|
73
|
+
while (true) {
|
|
74
|
+
const { done, value } = await reader.read();
|
|
75
|
+
if (done)
|
|
76
|
+
break;
|
|
77
|
+
chunks.push(value);
|
|
78
|
+
}
|
|
79
|
+
const concatenated = new Uint8Array(chunks.reduce((acc, chunk) => acc + chunk.length, 0));
|
|
80
|
+
let position = 0;
|
|
81
|
+
for (const chunk of chunks) {
|
|
82
|
+
concatenated.set(chunk, position);
|
|
83
|
+
position += chunk.length;
|
|
84
|
+
}
|
|
85
|
+
encodedData = concatenated;
|
|
76
86
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
for (const chunk of chunks) {
|
|
80
|
-
concatenated.set(chunk, position);
|
|
81
|
-
position += chunk.length;
|
|
87
|
+
else {
|
|
88
|
+
encodedData = body;
|
|
82
89
|
}
|
|
83
|
-
let data = new TextDecoder().decode(
|
|
90
|
+
let data = new TextDecoder().decode(encodedData);
|
|
84
91
|
let type;
|
|
85
92
|
if (contentType === 'application/json') {
|
|
86
93
|
try {
|
|
@@ -137,23 +144,19 @@ var nativeBridge = (function (exports) {
|
|
|
137
144
|
return { data: body, type: 'json' };
|
|
138
145
|
};
|
|
139
146
|
const CAPACITOR_HTTP_INTERCEPTOR = '/_capacitor_http_interceptor_';
|
|
140
|
-
const
|
|
147
|
+
const CAPACITOR_HTTP_INTERCEPTOR_URL_PARAM = 'u';
|
|
141
148
|
// TODO: export as Cap function
|
|
142
149
|
const isRelativeOrProxyUrl = (url) => !url ||
|
|
143
150
|
!(url.startsWith('http:') || url.startsWith('https:')) ||
|
|
144
|
-
url.indexOf(CAPACITOR_HTTP_INTERCEPTOR) > -1
|
|
145
|
-
url.indexOf(CAPACITOR_HTTPS_INTERCEPTOR) > -1;
|
|
151
|
+
url.indexOf(CAPACITOR_HTTP_INTERCEPTOR) > -1;
|
|
146
152
|
// TODO: export as Cap function
|
|
147
153
|
const createProxyUrl = (url, win) => {
|
|
148
154
|
var _a, _b;
|
|
149
155
|
if (isRelativeOrProxyUrl(url))
|
|
150
156
|
return url;
|
|
151
|
-
const proxyUrl = new URL(url);
|
|
152
157
|
const bridgeUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : '');
|
|
153
|
-
|
|
154
|
-
bridgeUrl.
|
|
155
|
-
bridgeUrl.hash = proxyUrl.hash;
|
|
156
|
-
bridgeUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${encodeURIComponent(proxyUrl.host)}${proxyUrl.pathname}`;
|
|
158
|
+
bridgeUrl.pathname = CAPACITOR_HTTP_INTERCEPTOR;
|
|
159
|
+
bridgeUrl.searchParams.append(CAPACITOR_HTTP_INTERCEPTOR_URL_PARAM, url);
|
|
157
160
|
return bridgeUrl.toString();
|
|
158
161
|
};
|
|
159
162
|
const initBridge = (w) => {
|
package/package.json
CHANGED