From a331912c75060c58077e03da315da411680bd21c Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 25 Nov 2023 00:00:54 +0800 Subject: [PATCH 1/4] Update cronet_client.dart --- pkgs/cronet_http/lib/src/cronet_client.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/cronet_http/lib/src/cronet_client.dart b/pkgs/cronet_http/lib/src/cronet_client.dart index c4d0d19006..0a435c9275 100644 --- a/pkgs/cronet_http/lib/src/cronet_client.dart +++ b/pkgs/cronet_http/lib/src/cronet_client.dart @@ -317,7 +317,7 @@ class CronetClient extends BaseClient { jb.UrlRequestCallbackProxy.new1( _urlRequestCallbacks(request, responseCompleter)), _executor, - ); + ).setHttpMethod(request.method.toJString()); var headers = request.headers; if (body.isNotEmpty && From f6a3d5159e72014779795ce8bc40473f73f7015c Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 25 Nov 2023 00:13:36 +0800 Subject: [PATCH 2/4] Update cronet_configuration_test.dart --- .../cronet_configuration_test.dart | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/cronet_http/example/integration_test/cronet_configuration_test.dart b/pkgs/cronet_http/example/integration_test/cronet_configuration_test.dart index f787ebc39a..4372e85432 100644 --- a/pkgs/cronet_http/example/integration_test/cronet_configuration_test.dart +++ b/pkgs/cronet_http/example/integration_test/cronet_configuration_test.dart @@ -2,9 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:convert'; import 'dart:io'; import 'package:cronet_http/cronet_http.dart'; +import 'package:http/http.dart'; import 'package:integration_test/integration_test.dart'; import 'package:test/test.dart'; @@ -92,6 +94,49 @@ void testInvalidConfigurations() { }); } +void testMethods() { + group('methods', () { + late HttpServer server; + late String requestMethod; + + setUp(() async { + server = (await HttpServer.bind('localhost', 0)) + ..listen((request) async { + await request.drain(); + requestMethod = request.method; + await request.response.close(); + }); + }); + tearDown(() { + server.close(); + }); + + test('methods', () async { + final engine = CronetEngine.build(); + const methods = [ + 'GET', + 'HEAD', + 'POST', + 'PUT', + 'DELETE', + 'CONNECT', + 'OPTIONS', + 'TRACE', + 'PATCH', + 'CUSTOM', + ]; + for (final method in methods) { + final request = Request( + method, + Uri.parse('http://localhost:${server.port}'), + ); + await CronetClient.fromCronetEngine(engine).send(request); + expect(requestMethod, method); + } + }); + }); +} + void testUserAgent() { group('userAgent', () { late HttpServer server; From f00861824f557439e7cd531604c591a1bce93d1b Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 25 Nov 2023 00:20:25 +0800 Subject: [PATCH 3/4] Fix format --- .../cronet_configuration_test.dart | 2 +- pkgs/cronet_http/lib/src/cronet_client.dart | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkgs/cronet_http/example/integration_test/cronet_configuration_test.dart b/pkgs/cronet_http/example/integration_test/cronet_configuration_test.dart index 4372e85432..71f83be8a2 100644 --- a/pkgs/cronet_http/example/integration_test/cronet_configuration_test.dart +++ b/pkgs/cronet_http/example/integration_test/cronet_configuration_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:convert'; import 'dart:io'; import 'package:cronet_http/cronet_http.dart'; @@ -170,5 +169,6 @@ void main() { testCache(); testInvalidConfigurations(); + testMethods(); testUserAgent(); } diff --git a/pkgs/cronet_http/lib/src/cronet_client.dart b/pkgs/cronet_http/lib/src/cronet_client.dart index 0a435c9275..92d2281eb2 100644 --- a/pkgs/cronet_http/lib/src/cronet_client.dart +++ b/pkgs/cronet_http/lib/src/cronet_client.dart @@ -312,12 +312,14 @@ class CronetClient extends BaseClient { final responseCompleter = Completer(); final engine = _engine!._engine; - final builder = engine.newUrlRequestBuilder( - request.url.toString().toJString(), - jb.UrlRequestCallbackProxy.new1( - _urlRequestCallbacks(request, responseCompleter)), - _executor, - ).setHttpMethod(request.method.toJString()); + final builder = engine + .newUrlRequestBuilder( + request.url.toString().toJString(), + jb.UrlRequestCallbackProxy.new1( + _urlRequestCallbacks(request, responseCompleter)), + _executor, + ) + .setHttpMethod(request.method.toJString()); var headers = request.headers; if (body.isNotEmpty && From ee9bb6cb10926437651bb5470d8dc663fcc6ae6b Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 25 Nov 2023 00:22:12 +0800 Subject: [PATCH 4/4] Update CHANGELOG.md --- pkgs/cronet_http/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/cronet_http/CHANGELOG.md b/pkgs/cronet_http/CHANGELOG.md index 7eecd298e0..5d11778cac 100644 --- a/pkgs/cronet_http/CHANGELOG.md +++ b/pkgs/cronet_http/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.4.3-wip +* Fix invalid requests method. + ## 0.4.2 * Require `package:jni >= 0.7.2` to remove a potential buffer overflow.