OLD | NEW |
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:isolate"; | 7 import "dart:isolate"; |
8 import "dart:io"; | 8 import "dart:io"; |
9 | 9 |
10 void testNoBody(int totalConnections, bool explicitContentLength) { | 10 void testNoBody(int totalConnections, bool explicitContentLength) { |
11 var errors = 0; | 11 var errors = 0; |
12 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) { | 12 HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) { |
13 server.listen( | 13 server.listen( |
14 (HttpRequest request) { | 14 (HttpRequest request) { |
15 Expect.equals("0", request.headers.value('content-length')); | 15 Expect.equals("0", request.headers.value('content-length')); |
16 Expect.equals(0, request.contentLength); | 16 Expect.equals(0, request.contentLength); |
17 var response = request.response; | 17 var response = request.response; |
18 response.contentLength = 0; | 18 response.contentLength = 0; |
19 response.done | 19 response.done |
20 .then((_) { | 20 .then((_) { |
21 Expect.fail("Unexpected successful response completion"); | 21 Expect.fail("Unexpected successful response completion"); |
22 }) | 22 }) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 String msg = "Unexpected error $e"; | 68 String msg = "Unexpected error $e"; |
69 var trace = getAttachedStackTrace(e); | 69 var trace = getAttachedStackTrace(e); |
70 if (trace != null) msg += "\nStackTrace: $trace"; | 70 if (trace != null) msg += "\nStackTrace: $trace"; |
71 Expect.fail(msg); | 71 Expect.fail(msg); |
72 }); | 72 }); |
73 } | 73 } |
74 }); | 74 }); |
75 } | 75 } |
76 | 76 |
77 void testBody(int totalConnections, bool useHeader) { | 77 void testBody(int totalConnections, bool useHeader) { |
78 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) { | 78 HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) { |
79 int serverCount = 0; | 79 int serverCount = 0; |
80 server.listen( | 80 server.listen( |
81 (HttpRequest request) { | 81 (HttpRequest request) { |
82 Expect.equals("2", request.headers.value('content-length')); | 82 Expect.equals("2", request.headers.value('content-length')); |
83 Expect.equals(2, request.contentLength); | 83 Expect.equals(2, request.contentLength); |
84 var response = request.response; | 84 var response = request.response; |
85 if (useHeader) { | 85 if (useHeader) { |
86 response.contentLength = 2; | 86 response.contentLength = 2; |
87 } else { | 87 } else { |
88 response.headers.set("content-length", 2); | 88 response.headers.set("content-length", 2); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 }, | 146 }, |
147 onError: (error) { | 147 onError: (error) { |
148 // Undefined what server response sends. | 148 // Undefined what server response sends. |
149 }); | 149 }); |
150 }); | 150 }); |
151 } | 151 } |
152 }); | 152 }); |
153 } | 153 } |
154 | 154 |
155 void testBodyChunked(int totalConnections, bool useHeader) { | 155 void testBodyChunked(int totalConnections, bool useHeader) { |
156 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) { | 156 HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) { |
157 server.listen( | 157 server.listen( |
158 (HttpRequest request) { | 158 (HttpRequest request) { |
159 Expect.isNull(request.headers.value('content-length')); | 159 Expect.isNull(request.headers.value('content-length')); |
160 Expect.equals(-1, request.contentLength); | 160 Expect.equals(-1, request.contentLength); |
161 var response = request.response; | 161 var response = request.response; |
162 if (useHeader) { | 162 if (useHeader) { |
163 response.contentLength = 2; | 163 response.contentLength = 2; |
164 response.headers.chunkedTransferEncoding = true; | 164 response.headers.chunkedTransferEncoding = true; |
165 } else { | 165 } else { |
166 response.headers.set("content-length", 2); | 166 response.headers.set("content-length", 2); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 String msg = "Unexpected error $e"; | 222 String msg = "Unexpected error $e"; |
223 var trace = getAttachedStackTrace(e); | 223 var trace = getAttachedStackTrace(e); |
224 if (trace != null) msg += "\nStackTrace: $trace"; | 224 if (trace != null) msg += "\nStackTrace: $trace"; |
225 Expect.fail(msg); | 225 Expect.fail(msg); |
226 }); | 226 }); |
227 } | 227 } |
228 }); | 228 }); |
229 } | 229 } |
230 | 230 |
231 void testSetContentLength() { | 231 void testSetContentLength() { |
232 HttpServer.bind().then((server) { | 232 HttpServer.bind("127.0.0.1", 0).then((server) { |
233 server.listen( | 233 server.listen( |
234 (HttpRequest request) { | 234 (HttpRequest request) { |
235 var response = request.response; | 235 var response = request.response; |
236 Expect.isNull(response.headers.value('content-length')); | 236 Expect.isNull(response.headers.value('content-length')); |
237 Expect.equals(-1, response.contentLength); | 237 Expect.equals(-1, response.contentLength); |
238 response.headers.set("content-length", 3); | 238 response.headers.set("content-length", 3); |
239 Expect.equals("3", response.headers.value('content-length')); | 239 Expect.equals("3", response.headers.value('content-length')); |
240 Expect.equals(3, response.contentLength); | 240 Expect.equals(3, response.contentLength); |
241 response.write("xxx"); | 241 response.write("xxx"); |
242 response.close(); | 242 response.close(); |
(...skipping 15 matching lines...) Expand all Loading... |
258 | 258 |
259 void main() { | 259 void main() { |
260 testNoBody(5, false); | 260 testNoBody(5, false); |
261 testNoBody(5, true); | 261 testNoBody(5, true); |
262 testBody(5, false); | 262 testBody(5, false); |
263 testBody(5, true); | 263 testBody(5, true); |
264 testBodyChunked(5, false); | 264 testBodyChunked(5, false); |
265 testBodyChunked(5, true); | 265 testBodyChunked(5, true); |
266 testSetContentLength(); | 266 testSetContentLength(); |
267 } | 267 } |
OLD | NEW |