@capacitor/android 8.3.1-nightly-20260414T153008.0 → 8.3.1
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/java/com/getcapacitor/plugin/util/CapacitorHttpUrlConnection.java
CHANGED
|
@@ -24,6 +24,7 @@ import java.util.Iterator;
|
|
|
24
24
|
import java.util.List;
|
|
25
25
|
import java.util.Locale;
|
|
26
26
|
import java.util.Map;
|
|
27
|
+
import java.util.UUID;
|
|
27
28
|
import javax.net.ssl.HttpsURLConnection;
|
|
28
29
|
import javax.net.ssl.SSLSocketFactory;
|
|
29
30
|
import org.json.JSONException;
|
|
@@ -224,7 +225,16 @@ public class CapacitorHttpUrlConnection implements ICapacitorHttpUrlConnection {
|
|
|
224
225
|
this.writeRequestBody(body.toString());
|
|
225
226
|
}
|
|
226
227
|
} else if (bodyType != null && bodyType.equals("formData")) {
|
|
227
|
-
|
|
228
|
+
String boundary = extractBoundaryFromContentType(contentType);
|
|
229
|
+
if (boundary == null) {
|
|
230
|
+
// If no boundary is provided, generate a random one and set the Content-Type header accordingly
|
|
231
|
+
// or otherwise servers will not be able to parse the request body. Browsers do this automatically
|
|
232
|
+
// but here we need to do this manually in order to comply with browser api behavior.
|
|
233
|
+
boundary = UUID.randomUUID().toString();
|
|
234
|
+
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
this.writeFormDataRequestBody(boundary, body.toJSArray());
|
|
228
238
|
} else {
|
|
229
239
|
this.writeRequestBody(body.toString());
|
|
230
240
|
}
|
|
@@ -260,9 +270,8 @@ public class CapacitorHttpUrlConnection implements ICapacitorHttpUrlConnection {
|
|
|
260
270
|
}
|
|
261
271
|
}
|
|
262
272
|
|
|
263
|
-
private void writeFormDataRequestBody(String
|
|
273
|
+
private void writeFormDataRequestBody(String boundary, JSArray entries) throws IOException, JSONException {
|
|
264
274
|
try (DataOutputStream os = new DataOutputStream(connection.getOutputStream())) {
|
|
265
|
-
String boundary = contentType.split(";")[1].split("=")[1];
|
|
266
275
|
String lineEnd = "\r\n";
|
|
267
276
|
String twoHyphens = "--";
|
|
268
277
|
|
|
@@ -303,6 +312,39 @@ public class CapacitorHttpUrlConnection implements ICapacitorHttpUrlConnection {
|
|
|
303
312
|
}
|
|
304
313
|
}
|
|
305
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Extracts the boundary value from the `Content-Type` header for multipart/form-data requests, if provided.
|
|
317
|
+
*
|
|
318
|
+
* The boundary value might be surrounded by double quotes (") which will be stripped away.
|
|
319
|
+
*
|
|
320
|
+
* @param contentType The `Content-Type` header string.
|
|
321
|
+
* @return The boundary value if found, otherwise `null`.
|
|
322
|
+
*/
|
|
323
|
+
public static String extractBoundaryFromContentType(String contentType) {
|
|
324
|
+
String boundaryPrefix = "boundary=";
|
|
325
|
+
int boundaryIndex = contentType.indexOf(boundaryPrefix);
|
|
326
|
+
if (boundaryIndex == -1) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Extract the substring starting right after "boundary="
|
|
331
|
+
String boundary = contentType.substring(boundaryIndex + boundaryPrefix.length());
|
|
332
|
+
|
|
333
|
+
// Find the end of the boundary value by looking for the next ";"
|
|
334
|
+
int endIndex = boundary.indexOf(";");
|
|
335
|
+
if (endIndex != -1) {
|
|
336
|
+
boundary = boundary.substring(0, endIndex);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Remove surrounding double quotes if present
|
|
340
|
+
boundary = boundary.trim();
|
|
341
|
+
if (boundary.startsWith("\"") && boundary.endsWith("\"")) {
|
|
342
|
+
boundary = boundary.substring(1, boundary.length() - 1);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return boundary;
|
|
346
|
+
}
|
|
347
|
+
|
|
306
348
|
/**
|
|
307
349
|
* Opens a communications link to the resource referenced by this
|
|
308
350
|
* URL, if such a connection has not already been established.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/android",
|
|
3
|
-
"version": "8.3.1
|
|
3
|
+
"version": "8.3.1",
|
|
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)",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"verify": "./gradlew clean lint build test -b capacitor/build.gradle"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@capacitor/core": "^8.3.0
|
|
26
|
+
"@capacitor/core": "^8.3.0"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|