Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: tests/standalone/io/http_100_continue.dart

Issue 1128873011: Add handling of HTTP '100 Continue' intermediate response (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_100_continue.dart
diff --git a/tests/standalone/io/http_100_continue.dart b/tests/standalone/io/http_100_continue.dart
new file mode 100644
index 0000000000000000000000000000000000000000..96411ec86727ef875cfd455e2c524c3c9e60fddc
--- /dev/null
+++ b/tests/standalone/io/http_100_continue.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// 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:async";
+import 'dart:convert';
+import "dart:io";
+
+import "package:expect/expect.dart";
+
+void test(responseBytes, bodyLength) async {
+ fullRequest(bytes) {
+ var len = bytes.length;
+ return len > 4 &&
+ bytes[len - 4] == 13 &&
+ bytes[len - 3] == 10 &&
+ bytes[len - 2] == 13 &&
+ bytes[len - 1] == 10;
+ }
+
+ handleSocket(socket) async {
+ var bytes = [];
+ await for (var data in socket) {
+ bytes.addAll(data);
+ if (fullRequest(bytes)) {
+ socket.add(responseBytes);
+ socket.close();
+ }
+ }
+ }
+
+ var server = await ServerSocket.bind('127.0.0.1', 0);
+ server.listen(handleSocket);
+
+ var client = new HttpClient();
+ var request =
+ await client.getUrl(Uri.parse('http://127.0.0.1:${server.port}/'));
+ var response = await request.close();
+ Expect.equals(response.statusCode, 200);
+ Expect.equals(bodyLength,
+ (await response.fold([], (p, e) => p..addAll(e))).length);
+ server.close();
+}
+
+main() {
+ var r1 = '''
+HTTP/1.1 100 Continue\r
+\r
+HTTP/1.1 200 OK\r
+\r
+''';
+
+ var r2 = '''
+HTTP/1.1 100 Continue\r
+My-Header-1: hello\r
+My-Header-2: world\r
+\r
+HTTP/1.1 200 OK\r
+\r
+''';
+
+ var r3 = '''
+HTTP/1.1 100 Continue\r
+\r
+HTTP/1.1 200 OK\r
+Content-Length: 2\r
+\r
+AB''';
+
+ test(ASCII.encode(r1), 0);
+ test(ASCII.encode(r2), 0);
+ test(ASCII.encode(r3), 2);
+}
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698