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

Side by Side Diff: tests/standalone/io/http_parser_test.dart

Issue 15256002: Rewrite parts of http-parser, to better handle connection errors and pausing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup. Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/http_parser.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:math'; 7 import 'dart:math';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 Expect.equals(value, headers[name][0])); 69 Expect.equals(value, headers[name][0]));
70 } 70 }
71 incoming.listen( 71 incoming.listen(
72 (List<int> data) { 72 (List<int> data) {
73 Expect.isFalse(upgraded); 73 Expect.isFalse(upgraded);
74 bytesReceived += data.length; 74 bytesReceived += data.length;
75 }, 75 },
76 onDone: () { 76 onDone: () {
77 Expect.isFalse(upgraded); 77 Expect.isFalse(upgraded);
78 port2.close(); 78 port2.close();
79 Expect.equals(expectedMethod, method);
80 Expect.stringEquals(expectedUri, uri.toString());
81 Expect.equals(expectedVersion, headers.protocolVersion);
82 if (upgrade) {
83 Expect.equals(0, bytesReceived);
84 // port1 is closed by the listener on the detached data.
85 } else {
86 Expect.equals(expectedBytesReceived, bytesReceived);
87 }
79 }); 88 });
80 89
81 if (upgraded) { 90 if (upgraded) {
82 port1.close(); 91 port1.close();
83 httpParser.detachIncoming().listen( 92 httpParser.detachIncoming().listen(
84 (List<int> data) { 93 (List<int> data) {
85 unparsedBytesReceived += data.length; 94 unparsedBytesReceived += data.length;
86 }, 95 },
87 onDone: () { 96 onDone: () {
88 Expect.equals(unparsedLength, unparsedBytesReceived); 97 Expect.equals(unparsedLength, unparsedBytesReceived);
89 port2.close(); 98 port2.close();
90 }); 99 });
91 } 100 }
92 101
93 incoming.dataDone.then((_) { 102 incoming.dataDone.then((_) {
94 port1.close(); 103 port1.close();
95 Expect.isFalse(upgraded); 104 Expect.isFalse(upgraded);
96 Expect.equals(expectedMethod, method);
97 Expect.stringEquals(expectedUri, uri.toString());
98 Expect.equals(expectedVersion, headers.protocolVersion);
99 if (upgrade) {
100 Expect.equals(0, bytesReceived);
101 // port1 is closed by the listener on the detached data.
102 } else {
103 Expect.equals(expectedBytesReceived, bytesReceived);
104 }
105 }); 105 });
106 }); 106 });
107 107
108 method = null; 108 method = null;
109 uri = null; 109 uri = null;
110 headers = null; 110 headers = null;
111 bytesReceived = 0; 111 bytesReceived = 0;
112 unparsedBytesReceived = 0; 112 unparsedBytesReceived = 0;
113 upgraded = false; 113 upgraded = false;
114 } 114 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 {int expectedTransferLength: 0, 180 {int expectedTransferLength: 0,
181 int expectedBytesReceived: 0, 181 int expectedBytesReceived: 0,
182 Map expectedHeaders: null, 182 Map expectedHeaders: null,
183 bool chunked: false, 183 bool chunked: false,
184 bool close: false, 184 bool close: false,
185 String responseToMethod: null, 185 String responseToMethod: null,
186 bool connectionClose: false, 186 bool connectionClose: false,
187 bool upgrade: false, 187 bool upgrade: false,
188 int unparsedLength: 0, 188 int unparsedLength: 0,
189 String expectedVersion: "1.1"}) { 189 String expectedVersion: "1.1"}) {
190 _HttpParser httpParser;
191 bool headersCompleteCalled;
192 bool dataEndCalled;
193 bool dataEndClose;
194 int statusCode;
195 String reasonPhrase;
196 HttpHeaders headers;
197 int contentLength;
198 int bytesReceived;
199 StreamController controller; 190 StreamController controller;
200 bool upgraded; 191 bool upgraded;
201 192
202 void reset() { 193 void reset() {
194 _HttpParser httpParser;
195 bool headersCompleteCalled;
196 bool dataEndCalled;
197 bool dataEndClose;
198 int statusCode;
199 String reasonPhrase;
200 HttpHeaders headers;
201 int contentLength;
202 int bytesReceived;
203 httpParser = new _HttpParser.responseParser(); 203 httpParser = new _HttpParser.responseParser();
204 controller = new StreamController(); 204 controller = new StreamController();
205 var port = new ReceivePort(); 205 var port = new ReceivePort();
206 controller.stream.pipe(httpParser); 206 controller.stream.pipe(httpParser);
207 var subscription = httpParser.listen((incoming) { 207 var subscription = httpParser.listen((incoming) {
208 port.close(); 208 port.close();
209 statusCode = incoming.statusCode; 209 statusCode = incoming.statusCode;
210 reasonPhrase = incoming.reasonPhrase; 210 reasonPhrase = incoming.reasonPhrase;
211 headers = incoming.headers; 211 headers = incoming.headers;
212 Expect.isFalse(headersCompleteCalled); 212 Expect.isFalse(headersCompleteCalled);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 "SEARCH", 331 "SEARCH",
332 // Methods with HTTP prefix. 332 // Methods with HTTP prefix.
333 "H", "HT", "HTT", "HTTP", "HX", "HTX", "HTTX", "HTTPX"]; 333 "H", "HT", "HTT", "HTTP", "HX", "HTX", "HTTX", "HTTPX"];
334 methods.forEach((method) { 334 methods.forEach((method) {
335 request = "$method / HTTP/1.1\r\n\r\n"; 335 request = "$method / HTTP/1.1\r\n\r\n";
336 _testParseRequest(request, method, "/"); 336 _testParseRequest(request, method, "/");
337 request = "$method /index.html HTTP/1.1\r\n\r\n"; 337 request = "$method /index.html HTTP/1.1\r\n\r\n";
338 _testParseRequest(request, method, "/index.html"); 338 _testParseRequest(request, method, "/index.html");
339 }); 339 });
340 340
341
342 request = "GET / HTTP/1.0\r\n\r\n"; 341 request = "GET / HTTP/1.0\r\n\r\n";
343 _testParseRequest(request, "GET", "/", 342 _testParseRequest(request, "GET", "/",
344 expectedVersion: "1.0", 343 expectedVersion: "1.0",
345 connectionClose: true); 344 connectionClose: true);
346 345
347 request = "GET / HTTP/1.0\r\nConnection: keep-alive\r\n\r\n"; 346 request = "GET / HTTP/1.0\r\nConnection: keep-alive\r\n\r\n";
348 _testParseRequest(request, "GET", "/", expectedVersion: "1.0"); 347 _testParseRequest(request, "GET", "/", expectedVersion: "1.0");
349 348
350 request = """ 349 request = """
351 POST /test HTTP/1.1\r 350 POST /test HTTP/1.1\r
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 395
397 request = """ 396 request = """
398 POST /test HTTP/1.1\r 397 POST /test HTTP/1.1\r
399 Header-A: AA\r 398 Header-A: AA\r
400 A\r 399 A\r
401 X-Header-B: b\r 400 X-Header-B: b\r
402 b\r 401 b\r
403 \t b\r 402 \t b\r
404 \r 403 \r
405 """; 404 """;
405
406 headers = new Map(); 406 headers = new Map();
407 headers["header-a"] = "AAA"; 407 headers["header-a"] = "AAA";
408 headers["x-header-b"] = "bbb"; 408 headers["x-header-b"] = "bbb";
409 _testParseRequest(request, "POST", "/test", expectedHeaders: headers); 409 _testParseRequest(request, "POST", "/test", expectedHeaders: headers);
410 410
411 request = """ 411 request = """
412 POST /test HTTP/1.1\r 412 POST /test HTTP/1.1\r
413 Content-Length: 10\r 413 Content-Length: 10\r
414 \r 414 \r
415 0123456789"""; 415 0123456789""";
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 0123456789012345678901234567890\r 867 0123456789012345678901234567890\r
868 0\r\n\r\n"""; 868 0\r\n\r\n""";
869 _testParseInvalidResponse(response); 869 _testParseInvalidResponse(response);
870 } 870 }
871 } 871 }
872 872
873 873
874 void main() { 874 void main() {
875 HttpParserTest.runAllTests(); 875 HttpParserTest.runAllTests();
876 } 876 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698