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

Side by Side Diff: tests/standalone/src/io/HttpParserTest.dart

Issue 10033023: Fix bug in HTTP header parsing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | « runtime/bin/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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #source("../../../../runtime/bin/http_parser.dart"); 5 #source("../../../../runtime/bin/http_parser.dart");
6 6
7 class HttpParserTest { 7 class HttpParserTest {
8 static void runAllTests() { 8 static void runAllTests() {
9 testParseRequest(); 9 testParseRequest();
10 testParseResponse(); 10 testParseResponse();
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 X-Header-B: bbb\r 293 X-Header-B: bbb\r
294 \r 294 \r
295 """; 295 """;
296 headers = new Map(); 296 headers = new Map();
297 headers["header-a"] = "AAA"; 297 headers["header-a"] = "AAA";
298 headers["x-header-b"] = "bbb"; 298 headers["x-header-b"] = "bbb";
299 _testParseRequest(request, "POST", "/test", expectedHeaders: headers); 299 _testParseRequest(request, "POST", "/test", expectedHeaders: headers);
300 300
301 request = """ 301 request = """
302 POST /test HTTP/1.1\r 302 POST /test HTTP/1.1\r
303 Empty-Header-1:\r
304 Empty-Header-2:\r
305 \r
306 \r
307 """;
308 headers = new Map();
309 headers["empty-header-1"] = "";
310 headers["empty-header-2"] = "";
311 _testParseRequest(request, "POST", "/test", expectedHeaders: headers);
312
313 request = """
314 POST /test HTTP/1.1\r
303 Header-A: AAA\r 315 Header-A: AAA\r
304 X-Header-B:\t \t bbb\r 316 X-Header-B:\t \t bbb\r
305 \r 317 \r
306 """; 318 """;
307 headers = new Map(); 319 headers = new Map();
308 headers["header-a"] = "AAA"; 320 headers["header-a"] = "AAA";
309 headers["x-header-b"] = "bbb"; 321 headers["x-header-b"] = "bbb";
310 _testParseRequest(request, "POST", "/test", expectedHeaders: headers); 322 _testParseRequest(request, "POST", "/test", expectedHeaders: headers);
311 323
312 request = """ 324 request = """
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 575
564 request = "@ / HTTP/1.1\r\n\r\n"; 576 request = "@ / HTTP/1.1\r\n\r\n";
565 _testParseInvalidRequest(request); 577 _testParseInvalidRequest(request);
566 578
567 request = "GET / TTP/1.1\r\n\r\n"; 579 request = "GET / TTP/1.1\r\n\r\n";
568 _testParseInvalidRequest(request); 580 _testParseInvalidRequest(request);
569 581
570 request = "GET / HTTP/1.\r\n\r\n"; 582 request = "GET / HTTP/1.\r\n\r\n";
571 _testParseInvalidRequest(request); 583 _testParseInvalidRequest(request);
572 584
585 request = "GET / HTTP/1.1\r\nKeep-Alive: False\r\nbadheader\r\n\r\n";
586 _testParseInvalidRequest(request);
587
573 // Currently no HTTP 1.0 support. 588 // Currently no HTTP 1.0 support.
574 request = "GET / HTTP/1.0\r\n\r\n"; 589 request = "GET / HTTP/1.0\r\n\r\n";
575 _testParseInvalidRequest(request); 590 _testParseInvalidRequest(request);
576
577 Expect.throws(() {
578 // TODO(2370): HTTP parser error.
579 request = "GET / HTTP/1.1\r\nKeep-Alive: False\r\nbadheader\r\n\r\n";
580 _testParseInvalidRequest(request);
581 });
582 } 591 }
583 592
584 static void testParseInvalidResponse() { 593 static void testParseInvalidResponse() {
585 String response; 594 String response;
586 595
587 response = "HTTP/1.1\r\nContent-Length: 0\r\n\r\n"; 596 response = "HTTP/1.1\r\nContent-Length: 0\r\n\r\n";
588 _testParseInvalidResponse(response); 597 _testParseInvalidResponse(response);
589 598
590 response = "HTTP/1.1 \r\nContent-Length: 0\r\n\r\n"; 599 response = "HTTP/1.1 \r\nContent-Length: 0\r\n\r\n";
591 _testParseInvalidResponse(response); 600 _testParseInvalidResponse(response);
(...skipping 18 matching lines...) Expand all
610 619
611 response = "HTTP/1.1 000 OK\r\nContent-Length: 0\r\n\r\n"; 620 response = "HTTP/1.1 000 OK\r\nContent-Length: 0\r\n\r\n";
612 _testParseInvalidResponse(response); 621 _testParseInvalidResponse(response);
613 622
614 response = "HTTP/1.1 999 Server Error\r\nContent-Length: 0\r\n\r\n"; 623 response = "HTTP/1.1 999 Server Error\r\nContent-Length: 0\r\n\r\n";
615 _testParseInvalidResponse(response); 624 _testParseInvalidResponse(response);
616 625
617 response = "HTTP/1.1 200 OK\r\nContent-Length: x\r\n\r\n"; 626 response = "HTTP/1.1 200 OK\r\nContent-Length: x\r\n\r\n";
618 _testParseInvalidResponse(response); 627 _testParseInvalidResponse(response);
619 628
629 response = "HTTP/1.1 200 OK\r\nbadheader\r\n\r\n";
630 _testParseInvalidResponse(response);
631
620 response = """ 632 response = """
621 HTTP/1.1 200 OK\r 633 HTTP/1.1 200 OK\r
622 Transfer-Encoding: chunked\r 634 Transfer-Encoding: chunked\r
623 \r 635 \r
624 1A\r 636 1A\r
625 01234567890123456789012345\r 637 01234567890123456789012345\r
626 1g\r 638 1g\r
627 0123456789012345678901234567890\r 639 0123456789012345678901234567890\r
628 0\r\n\r\n"""; 640 0\r\n\r\n""";
629 _testParseInvalidResponse(response); 641 _testParseInvalidResponse(response);
630 } 642 }
631 } 643 }
632 644
633 645
634 void main() { 646 void main() {
635 HttpParserTest.runAllTests(); 647 HttpParserTest.runAllTests();
636 } 648 }
OLDNEW
« no previous file with comments | « runtime/bin/http_parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698