From 0f1c46e346723c43598d114316c0871c5abc2514 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Mon, 11 Nov 2024 02:12:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Use=20`flutter-io.cn`?= =?UTF-8?q?=20rather=20than=20`neverssl.com`=20(#2325)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NeverSSL no longer supports H2 headers upgrade without TLS. All alternatives I've searched are not supported: - http://www.gstatic.com/generate_204 - http://http.badssl.com/ - http://flutter.dev/ Surprisingly, http://flutter-io.cn/ supports all functionality. 😮 --------- Signed-off-by: Luke Cheng <2258420+chenglu@users.noreply.github.com> Co-authored-by: Luke Cheng <2258420+chenglu@users.noreply.github.com> --- dio_test/lib/src/test/basic_tests.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dio_test/lib/src/test/basic_tests.dart b/dio_test/lib/src/test/basic_tests.dart index c6e589e1d..363f31a46 100644 --- a/dio_test/lib/src/test/basic_tests.dart +++ b/dio_test/lib/src/test/basic_tests.dart @@ -17,7 +17,7 @@ void basicTests( group('basic request', () { test( 'works with non-TLS requests', - () => dio.get('http://neverssl.com/'), + () => dio.get('http://flutter-io.cn/'), testOn: 'vm', ); From 540616204d73814fd07855ef0e0a3b88424ec0a5 Mon Sep 17 00:00:00 2001 From: Neo <43269594+helloliuyiming@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:50:42 +0800 Subject: [PATCH 2/2] Fix FormData clone boundary inconsistency issue (#2305) Resolves https://github.com/cfug/dio/issues/2303 ## Fix boundary inconsistency in FormData.clone method Description: This PR addresses an issue where cloning FormData objects resulted in different boundaries each time. The problem was caused by allocating a new boundary for each clone without any boundary reuse logic. Changes made: - Added an `initBoundary` parameter to the FormData constructor. - Implemented boundary reuse logic when cloning FormData objects. - Updated documentation to explain how `initBoundary` affects `boundaryName`. Technical details: - The `FormData` constructor now accepts an optional `initBoundary` parameter. - When `initBoundary` is provided, it overrides the `boundaryName` configuration. - The cloning process now reuses the existing boundary when appropriate. Impact: This fix ensures consistent behavior when cloning FormData objects and improves efficiency by reusing boundaries where possible. It should resolve issues related to unexpected boundary changes during FormData manipulation. Testing: - Added unit tests to verify boundary consistency across cloned FormData objects. - Manually tested with various use cases to ensure backward compatibility. --- dio/CHANGELOG.md | 1 + dio/lib/src/form_data.dart | 3 ++- dio/test/formdata_test.dart | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dio/CHANGELOG.md b/dio/CHANGELOG.md index 4a43995d3..4243c1626 100644 --- a/dio/CHANGELOG.md +++ b/dio/CHANGELOG.md @@ -7,6 +7,7 @@ See the [Migration Guide][] for the complete breaking changes list.** - Update comments and strings with `MultipartFile`. - Removes redundant warnings when composing request options on Web. +- Fixes boundary inconsistency in `FormData.clone()`. ## 5.7.0 diff --git a/dio/lib/src/form_data.dart b/dio/lib/src/form_data.dart index 10bc5f626..2fc4cd548 100644 --- a/dio/lib/src/form_data.dart +++ b/dio/lib/src/form_data.dart @@ -74,7 +74,7 @@ class FormData { /// /// See also: https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html String get boundary => _boundary; - late final String _boundary; + late String _boundary; /// The form fields to send for this request. final fields = >[]; @@ -210,6 +210,7 @@ class FormData { // Convenience method to clone finalized FormData when retrying requests. FormData clone() { final clone = FormData(); + clone._boundary = _boundary; clone.fields.addAll(fields); for (final file in files) { clone.files.add(MapEntry(file.key, file.value.clone())); diff --git a/dio/test/formdata_test.dart b/dio/test/formdata_test.dart index 109a53246..ee299ecdf 100644 --- a/dio/test/formdata_test.dart +++ b/dio/test/formdata_test.dart @@ -176,6 +176,7 @@ void main() async { expect(fm1 != fm, true); expect(fm1.files[0].value.filename, fm.files[0].value.filename); expect(fm1.fields, fm.fields); + expect(fm1.boundary, fm.boundary); }, testOn: 'vm', );