From f194a62da029695ecc5c1a532b7909c46123b3c4 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Wed, 29 Nov 2023 09:32:08 -0800 Subject: [PATCH] Check for method casing --- .../http/test/io/client_conformance_test.dart | 5 +++- .../lib/http_client_conformance_tests.dart | 18 +++++++++----- .../lib/src/request_methods_tests.dart | 24 +++++++++++++++---- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pkgs/http/test/io/client_conformance_test.dart b/pkgs/http/test/io/client_conformance_test.dart index 5d8f7f598d..7089112b15 100644 --- a/pkgs/http/test/io/client_conformance_test.dart +++ b/pkgs/http/test/io/client_conformance_test.dart @@ -10,5 +10,8 @@ import 'package:http_client_conformance_tests/http_client_conformance_tests.dart import 'package:test/test.dart'; void main() { - testAll(IOClient.new); + testAll(IOClient.new, + preservesMethodCase: + false // https://github.com/dart-lang/sdk/issues/54187 + ); } diff --git a/pkgs/http_client_conformance_tests/lib/http_client_conformance_tests.dart b/pkgs/http_client_conformance_tests/lib/http_client_conformance_tests.dart index 29edf37a93..bd83c02abb 100644 --- a/pkgs/http_client_conformance_tests/lib/http_client_conformance_tests.dart +++ b/pkgs/http_client_conformance_tests/lib/http_client_conformance_tests.dart @@ -51,14 +51,20 @@ export 'src/server_errors_test.dart' show testServerErrors; /// If [canWorkInIsolates] is `false` then tests that require that the [Client] /// work in Isolates other than the main isolate will be skipped. /// +/// If [preservesMethodCase] is `false` then tests that assume that the +/// [Client] preserves custom request method casing will be skipped. +/// /// The tests are run against a series of HTTP servers that are started by the /// tests. If the tests are run in the browser, then the test servers are /// started in another process. Otherwise, the test servers are run in-process. -void testAll(Client Function() clientFactory, - {bool canStreamRequestBody = true, - bool canStreamResponseBody = true, - bool redirectAlwaysAllowed = false, - bool canWorkInIsolates = true}) { +void testAll( + Client Function() clientFactory, { + bool canStreamRequestBody = true, + bool canStreamResponseBody = true, + bool redirectAlwaysAllowed = false, + bool canWorkInIsolates = true, + bool preservesMethodCase = false, +}) { testRequestBody(clientFactory()); testRequestBodyStreamed(clientFactory(), canStreamRequestBody: canStreamRequestBody); @@ -67,7 +73,7 @@ void testAll(Client Function() clientFactory, testResponseBodyStreamed(clientFactory(), canStreamResponseBody: canStreamResponseBody); testRequestHeaders(clientFactory()); - testRequestMethods(clientFactory()); + testRequestMethods(clientFactory(), preservesMethodCase: preservesMethodCase); testResponseHeaders(clientFactory()); testResponseStatusLine(clientFactory()); testRedirect(clientFactory(), redirectAlwaysAllowed: redirectAlwaysAllowed); diff --git a/pkgs/http_client_conformance_tests/lib/src/request_methods_tests.dart b/pkgs/http_client_conformance_tests/lib/src/request_methods_tests.dart index 6e679fd569..ec11387f3d 100644 --- a/pkgs/http_client_conformance_tests/lib/src/request_methods_tests.dart +++ b/pkgs/http_client_conformance_tests/lib/src/request_methods_tests.dart @@ -12,7 +12,11 @@ import 'request_methods_server_vm.dart' /// Tests that the [Client] correctly sends HTTP request methods /// (e.g. GET, HEAD). -void testRequestMethods(Client client) async { +/// +/// If [preservesMethodCase] is `false` then tests that assume that the +/// [Client] preserves custom request method casing will be skipped. +void testRequestMethods(Client client, + {bool preservesMethodCase = true}) async { group('request methods', () { late final String host; late final StreamChannel httpServerChannel; @@ -25,15 +29,27 @@ void testRequestMethods(Client client) async { }); tearDownAll(() => httpServerChannel.sink.add(null)); - test('custom method', () async { + test('custom method - not case preserving', () async { await client.send(Request( - 'CUSTOM', + 'CuStOm', Uri.http(host, ''), )); final method = await httpServerQueue.next as String; - expect('CUSTOM', method); + expect('CUSTOM', method.toUpperCase()); }); + test('custom method case preserving', () async { + await client.send(Request( + 'CuStOm', + Uri.http(host, ''), + )); + final method = await httpServerQueue.next as String; + expect('CuStOm', method); + }, + skip: preservesMethodCase + ? false + : 'does not preserve HTTP request method case'); + test('delete', () async { await client.delete(Uri.http(host, '')); final method = await httpServerQueue.next as String;