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

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

Issue 11637017: Change the HTTP Content-Length handling (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
« sdk/lib/io/http_parser.dart ('K') | « 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) 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 import "dart:isolate"; 5 import "dart:isolate";
6 import "dart:io"; 6 import "dart:io";
7 7
8 void testNoBody(int totalConnections, bool explicitContentLength) { 8 void testNoBody(int totalConnections, bool explicitContentLength) {
9 HttpServer server = new HttpServer(); 9 HttpServer server = new HttpServer();
10 server.onError = (e) => Expect.fail("Unexpected error $e"); 10 server.onError = (e) => Expect.fail("Unexpected error $e");
11 server.listen("127.0.0.1", 0, backlog: totalConnections); 11 server.listen("127.0.0.1", 0, backlog: totalConnections);
12 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { 12 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
13 Expect.isNull(request.headers.value('content-length')); 13 Expect.equals("0", request.headers.value('content-length'));
14 Expect.equals(0, request.contentLength); 14 Expect.equals(0, request.contentLength);
15 response.contentLength = 0; 15 response.contentLength = 0;
16 OutputStream stream = response.outputStream; 16 OutputStream stream = response.outputStream;
17 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 17 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
18 stream.close(); 18 stream.close();
19 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 19 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
20 }; 20 };
21 21
22 int count = 0; 22 int count = 0;
23 HttpClient client = new HttpClient(); 23 HttpClient client = new HttpClient();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 }; 92 };
93 } 93 }
94 } 94 }
95 95
96 void testHttp10() { 96 void testHttp10() {
97 HttpServer server = new HttpServer(); 97 HttpServer server = new HttpServer();
98 server.onError = (e) => Expect.fail("Unexpected error $e"); 98 server.onError = (e) => Expect.fail("Unexpected error $e");
99 server.listen("127.0.0.1", 0, backlog: 5); 99 server.listen("127.0.0.1", 0, backlog: 5);
100 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { 100 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
101 Expect.isNull(request.headers.value('content-length')); 101 Expect.isNull(request.headers.value('content-length'));
102 Expect.equals(0, request.contentLength); 102 Expect.equals(-1, request.contentLength);
103 response.contentLength = 0; 103 response.contentLength = 0;
104 OutputStream stream = response.outputStream; 104 OutputStream stream = response.outputStream;
105 Expect.equals("1.0", request.protocolVersion); 105 Expect.equals("1.0", request.protocolVersion);
106 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 106 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
107 stream.close(); 107 stream.close();
108 }; 108 };
109 109
110 Socket socket = new Socket("127.0.0.1", server.port); 110 Socket socket = new Socket("127.0.0.1", server.port);
111 socket.onConnect = () { 111 socket.onConnect = () {
112 List<int> buffer = new List<int>(1024); 112 List<int> buffer = new List<int>(1024);
113 socket.outputStream.writeString("GET / HTTP/1.0\r\n\r\n"); 113 socket.outputStream.writeString("GET / HTTP/1.0\r\n\r\n");
114 socket.onData = () => socket.readList(buffer, 0, buffer.length); 114 socket.onData = () => socket.readList(buffer, 0, buffer.length);
115 socket.onClosed = () { 115 socket.onClosed = () {
116 socket.close(true); 116 socket.close(true);
117 server.close(); 117 server.close();
118 }; 118 };
119 }; 119 };
120 } 120 }
121 121
122 void main() { 122 void main() {
123 testNoBody(5, false); 123 testNoBody(5, false);
124 testNoBody(5, true); 124 testNoBody(5, true);
125 testBody(5); 125 testBody(5);
126 testHttp10(); 126 testHttp10();
127 } 127 }
OLDNEW
« sdk/lib/io/http_parser.dart ('K') | « sdk/lib/io/http_parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698