@capacitor/android 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.
- package/capacitor/src/main/assets/native-bridge.js +25 -22
- package/capacitor/src/main/java/com/getcapacitor/Bridge.java +6 -1
- package/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java +2 -18
- package/capacitor/src/main/java/com/getcapacitor/plugin/util/CapacitorHttpUrlConnection.java +3 -1
- package/package.json +1 -1
|
@@ -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) => {
|
|
@@ -89,8 +89,13 @@ public class Bridge {
|
|
|
89
89
|
public static final String CAPACITOR_FILE_START = "/_capacitor_file_";
|
|
90
90
|
public static final String CAPACITOR_CONTENT_START = "/_capacitor_content_";
|
|
91
91
|
public static final String CAPACITOR_HTTP_INTERCEPTOR_START = "/_capacitor_http_interceptor_";
|
|
92
|
+
|
|
93
|
+
/** @deprecated CAPACITOR_HTTPS_INTERCEPTOR_START is no longer required. All proxied requests are handled via CAPACITOR_HTTP_INTERCEPTOR_START instead */
|
|
94
|
+
@Deprecated
|
|
92
95
|
public static final String CAPACITOR_HTTPS_INTERCEPTOR_START = "/_capacitor_https_interceptor_";
|
|
93
96
|
|
|
97
|
+
public static final String CAPACITOR_HTTP_INTERCEPTOR_URL_PARAM = "u";
|
|
98
|
+
|
|
94
99
|
public static final int DEFAULT_ANDROID_WEBVIEW_VERSION = 60;
|
|
95
100
|
public static final int MINIMUM_ANDROID_WEBVIEW_VERSION = 55;
|
|
96
101
|
public static final int DEFAULT_HUAWEI_WEBVIEW_VERSION = 10;
|
|
@@ -367,7 +372,7 @@ public class Bridge {
|
|
|
367
372
|
}
|
|
368
373
|
}
|
|
369
374
|
|
|
370
|
-
if (url.getScheme().equals("data")) {
|
|
375
|
+
if (url.getScheme().equals("data") || url.getScheme().equals("blob")) {
|
|
371
376
|
return false;
|
|
372
377
|
}
|
|
373
378
|
|
|
@@ -30,7 +30,6 @@ import java.io.InputStream;
|
|
|
30
30
|
import java.net.HttpURLConnection;
|
|
31
31
|
import java.net.URL;
|
|
32
32
|
import java.net.URLConnection;
|
|
33
|
-
import java.net.URLDecoder;
|
|
34
33
|
import java.nio.charset.StandardCharsets;
|
|
35
34
|
import java.util.ArrayList;
|
|
36
35
|
import java.util.HashMap;
|
|
@@ -172,13 +171,7 @@ public class WebViewLocalServer {
|
|
|
172
171
|
public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
|
|
173
172
|
Uri loadingUrl = request.getUrl();
|
|
174
173
|
|
|
175
|
-
if (
|
|
176
|
-
null != loadingUrl.getPath() &&
|
|
177
|
-
(
|
|
178
|
-
loadingUrl.getPath().startsWith(Bridge.CAPACITOR_HTTP_INTERCEPTOR_START) ||
|
|
179
|
-
loadingUrl.getPath().startsWith(Bridge.CAPACITOR_HTTPS_INTERCEPTOR_START)
|
|
180
|
-
)
|
|
181
|
-
) {
|
|
174
|
+
if (null != loadingUrl.getPath() && loadingUrl.getPath().startsWith(Bridge.CAPACITOR_HTTP_INTERCEPTOR_START)) {
|
|
182
175
|
Logger.debug("Handling CapacitorHttp request: " + loadingUrl);
|
|
183
176
|
try {
|
|
184
177
|
return handleCapacitorHttpRequest(request);
|
|
@@ -259,16 +252,7 @@ public class WebViewLocalServer {
|
|
|
259
252
|
}
|
|
260
253
|
|
|
261
254
|
private WebResourceResponse handleCapacitorHttpRequest(WebResourceRequest request) throws IOException {
|
|
262
|
-
|
|
263
|
-
request.getUrl().getPath() != null && request.getUrl().getPath().startsWith(Bridge.CAPACITOR_HTTPS_INTERCEPTOR_START);
|
|
264
|
-
|
|
265
|
-
String urlString = request
|
|
266
|
-
.getUrl()
|
|
267
|
-
.toString()
|
|
268
|
-
.replace(bridge.getLocalUrl(), isHttps ? "https:/" : "http:/")
|
|
269
|
-
.replace(Bridge.CAPACITOR_HTTP_INTERCEPTOR_START, "")
|
|
270
|
-
.replace(Bridge.CAPACITOR_HTTPS_INTERCEPTOR_START, "");
|
|
271
|
-
urlString = URLDecoder.decode(urlString, "UTF-8");
|
|
255
|
+
String urlString = request.getUrl().getQueryParameter(Bridge.CAPACITOR_HTTP_INTERCEPTOR_URL_PARAM);
|
|
272
256
|
URL url = new URL(urlString);
|
|
273
257
|
JSObject headers = new JSObject();
|
|
274
258
|
|
package/capacitor/src/main/java/com/getcapacitor/plugin/util/CapacitorHttpUrlConnection.java
CHANGED
|
@@ -275,7 +275,7 @@ public class CapacitorHttpUrlConnection implements ICapacitorHttpUrlConnection {
|
|
|
275
275
|
if (type.equals("string")) {
|
|
276
276
|
os.writeBytes(twoHyphens + boundary + lineEnd);
|
|
277
277
|
os.writeBytes("Content-Disposition: form-data; name=\"" + key + "\"" + lineEnd + lineEnd);
|
|
278
|
-
os.
|
|
278
|
+
os.write(value.getBytes(StandardCharsets.UTF_8));
|
|
279
279
|
os.writeBytes(lineEnd);
|
|
280
280
|
} else if (type.equals("base64File")) {
|
|
281
281
|
String fileName = entry.getString("fileName");
|
|
@@ -289,6 +289,8 @@ public class CapacitorHttpUrlConnection implements ICapacitorHttpUrlConnection {
|
|
|
289
289
|
|
|
290
290
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
291
291
|
os.write(Base64.getDecoder().decode(value));
|
|
292
|
+
} else {
|
|
293
|
+
os.write(android.util.Base64.decode(value, android.util.Base64.DEFAULT));
|
|
292
294
|
}
|
|
293
295
|
|
|
294
296
|
os.writeBytes(lineEnd);
|
package/package.json
CHANGED