OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library shelf_io_test; | 5 library shelf_io_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 }, 'localhost', 0).then((server) { | 244 }, 'localhost', 0).then((server) { |
245 return http.get('http://localhost:${server.port}').then((response) { | 245 return http.get('http://localhost:${server.port}').then((response) { |
246 expect(response.statusCode, HttpStatus.OK); | 246 expect(response.statusCode, HttpStatus.OK); |
247 expect(response.body, 'Hello from /'); | 247 expect(response.body, 'Hello from /'); |
248 server.close(); | 248 server.close(); |
249 }); | 249 }); |
250 }); | 250 }); |
251 }); | 251 }); |
252 }); | 252 }); |
253 | 253 |
| 254 test('a bad HTTP request results in a 500 response', () { |
| 255 var socket; |
| 256 |
| 257 _scheduleServer(syncHandler); |
| 258 |
| 259 schedule(() { |
| 260 return Socket.connect('localhost', _serverPort).then((value) { |
| 261 socket = value; |
| 262 |
| 263 currentSchedule.onComplete.schedule(() { |
| 264 return socket.close(); |
| 265 }, 'close the socket'); |
| 266 }); |
| 267 }); |
| 268 |
| 269 schedule(() { |
| 270 socket.write('GET / HTTP/1.1\r\n'); |
| 271 socket.write('Host: ^^super bad !@#host\r\n'); |
| 272 socket.write('\r\n'); |
| 273 return socket.close(); |
| 274 }); |
| 275 |
| 276 schedule(() { |
| 277 return UTF8.decodeStream(socket).then((value) { |
| 278 expect(value, contains('500 Internal Server Error')); |
| 279 }); |
| 280 }); |
| 281 }); |
| 282 |
254 group('date header', () { | 283 group('date header', () { |
255 test('is sent by default', () { | 284 test('is sent by default', () { |
256 _scheduleServer(syncHandler); | 285 _scheduleServer(syncHandler); |
257 | 286 |
258 // Update beforeRequest to be one second earlier. HTTP dates only have | 287 // Update beforeRequest to be one second earlier. HTTP dates only have |
259 // second-level granularity and the request will likely take less than a | 288 // second-level granularity and the request will likely take less than a |
260 // second. | 289 // second. |
261 var beforeRequest = new DateTime.now().subtract(new Duration(seconds: 1)); | 290 var beforeRequest = new DateTime.now().subtract(new Duration(seconds: 1)); |
262 | 291 |
263 return _scheduleGet().then((response) { | 292 return _scheduleGet().then((response) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 364 |
336 var request = new http.Request('POST', | 365 var request = new http.Request('POST', |
337 Uri.parse('http://localhost:$_serverPort/')); | 366 Uri.parse('http://localhost:$_serverPort/')); |
338 | 367 |
339 if (headers != null) request.headers.addAll(headers); | 368 if (headers != null) request.headers.addAll(headers); |
340 if (body != null) request.body = body; | 369 if (body != null) request.body = body; |
341 | 370 |
342 return request.send(); | 371 return request.send(); |
343 }); | 372 }); |
344 } | 373 } |
OLD | NEW |