Skip to content

Commit

Permalink
Check for method casing
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Nov 29, 2023
1 parent 20f402c commit f194a62
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
5 changes: 4 additions & 1 deletion pkgs/http/test/io/client_conformance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object?> httpServerChannel;
Expand All @@ -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;
Expand Down

0 comments on commit f194a62

Please sign in to comment.