@capacitor/android 4.6.4-nightly-20230221T150532.0 → 4.7.0
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/CHANGELOG.md +19 -0
- package/capacitor/src/main/assets/native-bridge.js +8 -4
- package/capacitor/src/main/java/com/getcapacitor/ProcessedRoute.java +9 -0
- package/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java +4 -0
- package/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorHttp.java +1 -0
- package/capacitor/src/main/java/com/getcapacitor/plugin/util/CapacitorHttpUrlConnection.java +16 -0
- package/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java +24 -17
- package/capacitor/src/main/java/com/getcapacitor/plugin/util/ICapacitorHttpUrlConnection.java +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.7.0](https://github.com/ionic-team/capacitor/compare/4.6.3...4.7.0) (2023-02-22)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* handle fetch headers that are Headers objects ([#6320](https://github.com/ionic-team/capacitor/issues/6320)) ([cb00e49](https://github.com/ionic-team/capacitor/commit/cb00e4952acca8e877555f30b2190f6685d25934))
|
|
12
|
+
* **ios:** Correctly Attach Headers to Request ([#6303](https://github.com/ionic-team/capacitor/issues/6303)) ([a3f875c](https://github.com/ionic-team/capacitor/commit/a3f875cf42e111fde07d6e87643264b19ed77573))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **android:** add ability to create config from a custom file path ([#6264](https://github.com/ionic-team/capacitor/issues/6264)) ([42b4f0f](https://github.com/ionic-team/capacitor/commit/42b4f0f416c8038ae368860007910bb09c8ec84e))
|
|
18
|
+
* **android:** Add SSL Pinning logic ([#6314](https://github.com/ionic-team/capacitor/issues/6314)) ([07f113e](https://github.com/ionic-team/capacitor/commit/07f113e6933e15c45d772f69f7128cbb3706f7b9))
|
|
19
|
+
* **android:** enable loading of assets outside of the content web asset directory ([#6301](https://github.com/ionic-team/capacitor/issues/6301)) ([364497d](https://github.com/ionic-team/capacitor/commit/364497d4aca93fc716a0673ef9103479aed791ec))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [4.6.3](https://github.com/ionic-team/capacitor/compare/4.6.2...4.6.3) (2023-02-03)
|
|
7
26
|
|
|
8
27
|
|
|
@@ -374,13 +374,15 @@ var nativeBridge = (function (exports) {
|
|
|
374
374
|
console.time(tag);
|
|
375
375
|
try {
|
|
376
376
|
// intercept request & pass to the bridge
|
|
377
|
+
let headers = options === null || options === void 0 ? void 0 : options.headers;
|
|
378
|
+
if ((options === null || options === void 0 ? void 0 : options.headers) instanceof Headers) {
|
|
379
|
+
headers = Object.fromEntries(options.headers.entries());
|
|
380
|
+
}
|
|
377
381
|
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
|
|
378
382
|
url: resource,
|
|
379
383
|
method: (options === null || options === void 0 ? void 0 : options.method) ? options.method : undefined,
|
|
380
384
|
data: (options === null || options === void 0 ? void 0 : options.body) ? options.body : undefined,
|
|
381
|
-
headers:
|
|
382
|
-
? JSON.stringify(options.headers)
|
|
383
|
-
: undefined,
|
|
385
|
+
headers: headers,
|
|
384
386
|
});
|
|
385
387
|
const data = typeof nativeResponse.data === 'string'
|
|
386
388
|
? nativeResponse.data
|
|
@@ -508,7 +510,9 @@ var nativeBridge = (function (exports) {
|
|
|
508
510
|
url: this._url,
|
|
509
511
|
method: this._method,
|
|
510
512
|
data: body !== null ? body : undefined,
|
|
511
|
-
headers:
|
|
513
|
+
headers: this._headers != null && Object.keys(this._headers).length > 0
|
|
514
|
+
? this._headers
|
|
515
|
+
: undefined,
|
|
512
516
|
})
|
|
513
517
|
.then((nativeResponse) => {
|
|
514
518
|
// intercept & parse response before returning
|
|
@@ -9,6 +9,7 @@ public class ProcessedRoute {
|
|
|
9
9
|
|
|
10
10
|
private String path;
|
|
11
11
|
private boolean isAsset;
|
|
12
|
+
private boolean ignoreAssetPath;
|
|
12
13
|
|
|
13
14
|
public String getPath() {
|
|
14
15
|
return path;
|
|
@@ -25,4 +26,12 @@ public class ProcessedRoute {
|
|
|
25
26
|
public void setAsset(boolean asset) {
|
|
26
27
|
isAsset = asset;
|
|
27
28
|
}
|
|
29
|
+
|
|
30
|
+
public boolean isIgnoreAssetPath() {
|
|
31
|
+
return ignoreAssetPath;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public void setIgnoreAssetPath(boolean ignoreAssetPath) {
|
|
35
|
+
this.ignoreAssetPath = ignoreAssetPath;
|
|
36
|
+
}
|
|
28
37
|
}
|
|
@@ -484,10 +484,12 @@ public class WebViewLocalServer {
|
|
|
484
484
|
|
|
485
485
|
// Pass path to routeProcessor if present
|
|
486
486
|
RouteProcessor routeProcessor = bridge.getRouteProcessor();
|
|
487
|
+
boolean ignoreAssetPath = false;
|
|
487
488
|
if (routeProcessor != null) {
|
|
488
489
|
ProcessedRoute processedRoute = bridge.getRouteProcessor().process("", path);
|
|
489
490
|
path = processedRoute.getPath();
|
|
490
491
|
isAsset = processedRoute.isAsset();
|
|
492
|
+
ignoreAssetPath = processedRoute.isIgnoreAssetPath();
|
|
491
493
|
}
|
|
492
494
|
|
|
493
495
|
try {
|
|
@@ -501,6 +503,8 @@ public class WebViewLocalServer {
|
|
|
501
503
|
}
|
|
502
504
|
|
|
503
505
|
stream = protocolHandler.openFile(path);
|
|
506
|
+
} else if (ignoreAssetPath) {
|
|
507
|
+
stream = protocolHandler.openAsset(path);
|
|
504
508
|
} else {
|
|
505
509
|
stream = protocolHandler.openAsset(assetPath + path);
|
|
506
510
|
}
|
package/capacitor/src/main/java/com/getcapacitor/plugin/util/CapacitorHttpUrlConnection.java
CHANGED
|
@@ -3,6 +3,7 @@ package com.getcapacitor.plugin.util;
|
|
|
3
3
|
import android.os.Build;
|
|
4
4
|
import android.os.LocaleList;
|
|
5
5
|
import android.text.TextUtils;
|
|
6
|
+
import com.getcapacitor.Bridge;
|
|
6
7
|
import com.getcapacitor.JSArray;
|
|
7
8
|
import com.getcapacitor.JSObject;
|
|
8
9
|
import com.getcapacitor.JSValue;
|
|
@@ -10,6 +11,7 @@ import com.getcapacitor.PluginCall;
|
|
|
10
11
|
import java.io.DataOutputStream;
|
|
11
12
|
import java.io.IOException;
|
|
12
13
|
import java.io.InputStream;
|
|
14
|
+
import java.lang.reflect.Method;
|
|
13
15
|
import java.net.HttpURLConnection;
|
|
14
16
|
import java.net.ProtocolException;
|
|
15
17
|
import java.net.SocketTimeoutException;
|
|
@@ -21,6 +23,8 @@ import java.util.Iterator;
|
|
|
21
23
|
import java.util.List;
|
|
22
24
|
import java.util.Locale;
|
|
23
25
|
import java.util.Map;
|
|
26
|
+
import javax.net.ssl.HttpsURLConnection;
|
|
27
|
+
import javax.net.ssl.SSLSocketFactory;
|
|
24
28
|
import org.json.JSONException;
|
|
25
29
|
|
|
26
30
|
public class CapacitorHttpUrlConnection implements ICapacitorHttpUrlConnection {
|
|
@@ -363,4 +367,16 @@ public class CapacitorHttpUrlConnection implements ICapacitorHttpUrlConnection {
|
|
|
363
367
|
}
|
|
364
368
|
return result;
|
|
365
369
|
}
|
|
370
|
+
|
|
371
|
+
public void setSSLSocketFactory(Bridge bridge) {
|
|
372
|
+
// Attach SSL Certificates if Enterprise Plugin is available
|
|
373
|
+
try {
|
|
374
|
+
Class<?> sslPinningImpl = Class.forName("io.ionic.sslpinning.SSLPinning");
|
|
375
|
+
Method method = sslPinningImpl.getDeclaredMethod("getSSLSocketFactory", Bridge.class);
|
|
376
|
+
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) method.invoke(sslPinningImpl.newInstance(), bridge);
|
|
377
|
+
if (sslSocketFactory != null) {
|
|
378
|
+
((HttpsURLConnection) this.connection).setSSLSocketFactory(sslSocketFactory);
|
|
379
|
+
}
|
|
380
|
+
} catch (Exception ignored) {}
|
|
381
|
+
}
|
|
366
382
|
}
|
|
@@ -2,6 +2,7 @@ package com.getcapacitor.plugin.util;
|
|
|
2
2
|
|
|
3
3
|
import android.text.TextUtils;
|
|
4
4
|
import android.util.Base64;
|
|
5
|
+
import com.getcapacitor.Bridge;
|
|
5
6
|
import com.getcapacitor.JSArray;
|
|
6
7
|
import com.getcapacitor.JSObject;
|
|
7
8
|
import com.getcapacitor.JSValue;
|
|
@@ -26,6 +27,8 @@ import org.json.JSONObject;
|
|
|
26
27
|
|
|
27
28
|
public class HttpRequestHandler {
|
|
28
29
|
|
|
30
|
+
public static Bridge bridge = null;
|
|
31
|
+
|
|
29
32
|
/**
|
|
30
33
|
* An enum specifying conventional HTTP Response Types
|
|
31
34
|
* See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType
|
|
@@ -45,7 +48,7 @@ public class HttpRequestHandler {
|
|
|
45
48
|
|
|
46
49
|
static final ResponseType DEFAULT = TEXT;
|
|
47
50
|
|
|
48
|
-
static ResponseType parse(String value) {
|
|
51
|
+
public static ResponseType parse(String value) {
|
|
49
52
|
for (ResponseType responseType : values()) {
|
|
50
53
|
if (responseType.name.equalsIgnoreCase(value)) {
|
|
51
54
|
return responseType;
|
|
@@ -58,16 +61,16 @@ public class HttpRequestHandler {
|
|
|
58
61
|
/**
|
|
59
62
|
* Internal builder class for building a CapacitorHttpUrlConnection
|
|
60
63
|
*/
|
|
61
|
-
|
|
64
|
+
public static class HttpURLConnectionBuilder {
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
public Integer connectTimeout;
|
|
67
|
+
public Integer readTimeout;
|
|
68
|
+
public Boolean disableRedirects;
|
|
69
|
+
public JSObject headers;
|
|
70
|
+
public String method;
|
|
71
|
+
public URL url;
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
public CapacitorHttpUrlConnection connection;
|
|
71
74
|
|
|
72
75
|
public HttpURLConnectionBuilder setConnectTimeout(Integer connectTimeout) {
|
|
73
76
|
this.connectTimeout = connectTimeout;
|
|
@@ -188,7 +191,7 @@ public class HttpRequestHandler {
|
|
|
188
191
|
* @throws IOException Thrown if the InputStream is unable to be parsed correctly
|
|
189
192
|
* @throws JSONException Thrown if the JSON is unable to be parsed
|
|
190
193
|
*/
|
|
191
|
-
|
|
194
|
+
public static JSObject buildResponse(CapacitorHttpUrlConnection connection) throws IOException, JSONException {
|
|
192
195
|
return buildResponse(connection, ResponseType.DEFAULT);
|
|
193
196
|
}
|
|
194
197
|
|
|
@@ -200,7 +203,7 @@ public class HttpRequestHandler {
|
|
|
200
203
|
* @throws IOException Thrown if the InputStream is unable to be parsed correctly
|
|
201
204
|
* @throws JSONException Thrown if the JSON is unable to be parsed
|
|
202
205
|
*/
|
|
203
|
-
|
|
206
|
+
public static JSObject buildResponse(CapacitorHttpUrlConnection connection, ResponseType responseType)
|
|
204
207
|
throws IOException, JSONException {
|
|
205
208
|
int statusCode = connection.getResponseCode();
|
|
206
209
|
|
|
@@ -226,7 +229,7 @@ public class HttpRequestHandler {
|
|
|
226
229
|
* @throws IOException Thrown if the InputStreams cannot be properly parsed
|
|
227
230
|
* @throws JSONException Thrown if the JSON is malformed when parsing as JSON
|
|
228
231
|
*/
|
|
229
|
-
static Object readData(ICapacitorHttpUrlConnection connection, ResponseType responseType) throws IOException, JSONException {
|
|
232
|
+
public static Object readData(ICapacitorHttpUrlConnection connection, ResponseType responseType) throws IOException, JSONException {
|
|
230
233
|
InputStream errorStream = connection.getErrorStream();
|
|
231
234
|
String contentType = connection.getHeaderField("Content-Type");
|
|
232
235
|
|
|
@@ -261,7 +264,7 @@ public class HttpRequestHandler {
|
|
|
261
264
|
* @param mimeTypes The Mime-Type values to check against
|
|
262
265
|
* @return
|
|
263
266
|
*/
|
|
264
|
-
|
|
267
|
+
public static boolean isOneOf(String contentType, MimeType... mimeTypes) {
|
|
265
268
|
if (contentType != null) {
|
|
266
269
|
for (MimeType mimeType : mimeTypes) {
|
|
267
270
|
if (contentType.contains(mimeType.getValue())) {
|
|
@@ -277,7 +280,7 @@ public class HttpRequestHandler {
|
|
|
277
280
|
* @param connection The CapacitorHttpUrlConnection connection
|
|
278
281
|
* @return A JSObject of the header values from the CapacitorHttpUrlConnection
|
|
279
282
|
*/
|
|
280
|
-
|
|
283
|
+
public static JSObject buildResponseHeaders(CapacitorHttpUrlConnection connection) {
|
|
281
284
|
JSObject output = new JSObject();
|
|
282
285
|
|
|
283
286
|
for (Map.Entry<String, List<String>> entry : connection.getHeaderFields().entrySet()) {
|
|
@@ -294,7 +297,7 @@ public class HttpRequestHandler {
|
|
|
294
297
|
* @return A JSObject or JSArray
|
|
295
298
|
* @throws JSONException thrown if the JSON is malformed
|
|
296
299
|
*/
|
|
297
|
-
|
|
300
|
+
public static Object parseJSON(String input) throws JSONException {
|
|
298
301
|
JSONObject json = new JSONObject();
|
|
299
302
|
try {
|
|
300
303
|
if ("null".equals(input.trim())) {
|
|
@@ -323,7 +326,7 @@ public class HttpRequestHandler {
|
|
|
323
326
|
* @return String value of InputStream
|
|
324
327
|
* @throws IOException thrown if the InputStream is unable to be read as base64
|
|
325
328
|
*/
|
|
326
|
-
|
|
329
|
+
public static String readStreamAsBase64(InputStream in) throws IOException {
|
|
327
330
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
328
331
|
byte[] buffer = new byte[1024];
|
|
329
332
|
int readBytes;
|
|
@@ -341,7 +344,7 @@ public class HttpRequestHandler {
|
|
|
341
344
|
* @return String value of InputStream
|
|
342
345
|
* @throws IOException thrown if the InputStream is unable to be read
|
|
343
346
|
*/
|
|
344
|
-
|
|
347
|
+
public static String readStreamAsString(InputStream in) throws IOException {
|
|
345
348
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
|
|
346
349
|
StringBuilder builder = new StringBuilder();
|
|
347
350
|
String line = reader.readLine();
|
|
@@ -391,6 +394,10 @@ public class HttpRequestHandler {
|
|
|
391
394
|
|
|
392
395
|
CapacitorHttpUrlConnection connection = connectionBuilder.build();
|
|
393
396
|
|
|
397
|
+
if (null != bridge) {
|
|
398
|
+
connection.setSSLSocketFactory(bridge);
|
|
399
|
+
}
|
|
400
|
+
|
|
394
401
|
// Set HTTP body on a non GET or HEAD request
|
|
395
402
|
if (isHttpMutate) {
|
|
396
403
|
JSValue data = new JSValue(call, "data");
|
package/capacitor/src/main/java/com/getcapacitor/plugin/util/ICapacitorHttpUrlConnection.java
CHANGED
|
@@ -6,7 +6,7 @@ import java.io.InputStream;
|
|
|
6
6
|
/**
|
|
7
7
|
* This interface was extracted from {@link CapacitorHttpUrlConnection} to enable mocking that class.
|
|
8
8
|
*/
|
|
9
|
-
interface ICapacitorHttpUrlConnection {
|
|
9
|
+
public interface ICapacitorHttpUrlConnection {
|
|
10
10
|
InputStream getErrorStream();
|
|
11
11
|
|
|
12
12
|
String getHeaderField(String name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/android",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "Capacitor: Cross-platform apps with JavaScript and the web",
|
|
5
5
|
"homepage": "https://capacitorjs.com",
|
|
6
6
|
"author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "89cddcd6497034146e0938ce8c264e22e7baba52"
|
|
32
32
|
}
|