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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 }); | 277 }); |
278 }); | 278 }); |
279 | 279 |
280 return _scheduleGet().then((response) { | 280 return _scheduleGet().then((response) { |
281 expect(response.headers, contains('date')); | 281 expect(response.headers, contains('date')); |
282 var responseDate = parser.parseHttpDate(response.headers['date']); | 282 var responseDate = parser.parseHttpDate(response.headers['date']); |
283 expect(responseDate, date); | 283 expect(responseDate, date); |
284 }); | 284 }); |
285 }); | 285 }); |
286 }); | 286 }); |
287 | |
288 group('server header', () { | |
289 test('defaults to "dart:io with Shelf"', () { | |
290 _scheduleServer(syncHandler); | |
291 | |
292 return _scheduleGet().then((response) { | |
293 expect(response.headers, containsPair(HttpHeaders.SERVER, 'dart:io with Shelf')); | |
nweiz
2014/05/27 23:08:05
Long line
kevmoo
2014/05/28 00:44:05
Done.
| |
294 }); | |
295 }); | |
296 | |
297 test('deferres to response header when', () { | |
nweiz
2014/05/27 23:08:05
"deferres" -> "defers", "response header when" ->
kevmoo
2014/05/28 00:44:05
Done.
| |
298 _scheduleServer((request) { | |
299 return new Response.ok('test', | |
300 headers: {HttpHeaders.SERVER: 'myServer'}); | |
301 }); | |
302 | |
303 return _scheduleGet().then((response) { | |
304 expect(response.headers, containsPair(HttpHeaders.SERVER, 'myServer')); | |
305 }); | |
306 }); | |
307 }); | |
287 } | 308 } |
288 | 309 |
289 int _serverPort; | 310 int _serverPort; |
290 | 311 |
291 Future _scheduleServer(Handler handler) { | 312 Future _scheduleServer(Handler handler) { |
292 return schedule(() => shelf_io.serve(handler, 'localhost', 0).then((server) { | 313 return schedule(() => shelf_io.serve(handler, 'localhost', 0).then((server) { |
293 currentSchedule.onComplete.schedule(() { | 314 currentSchedule.onComplete.schedule(() { |
294 _serverPort = null; | 315 _serverPort = null; |
295 return server.close(force: true); | 316 return server.close(force: true); |
296 }); | 317 }); |
(...skipping 16 matching lines...) Expand all Loading... | |
313 | 334 |
314 var request = new http.Request('POST', | 335 var request = new http.Request('POST', |
315 Uri.parse('http://localhost:$_serverPort/')); | 336 Uri.parse('http://localhost:$_serverPort/')); |
316 | 337 |
317 if (headers != null) request.headers.addAll(headers); | 338 if (headers != null) request.headers.addAll(headers); |
318 if (body != null) request.body = body; | 339 if (body != null) request.body = body; |
319 | 340 |
320 return request.send(); | 341 return request.send(); |
321 }); | 342 }); |
322 } | 343 } |
OLD | NEW |