| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 "Content-Length: 13\r\n" | 199 "Content-Length: 13\r\n" |
| 200 "\r\n" | 200 "\r\n" |
| 201 "Hello, world!").codeUnits); | 201 "Hello, world!").codeUnits); |
| 202 sink.close(); | 202 sink.close(); |
| 203 })); | 203 })); |
| 204 }); | 204 }); |
| 205 | 205 |
| 206 return _schedulePost(body: "Hello").then((response) { | 206 return _schedulePost(body: "Hello").then((response) { |
| 207 expect(response.statusCode, HttpStatus.NOT_FOUND); | 207 expect(response.statusCode, HttpStatus.NOT_FOUND); |
| 208 expect(response.headers["date"], "Mon, 23 May 2005 22:38:34 GMT"); | 208 expect(response.headers["date"], "Mon, 23 May 2005 22:38:34 GMT"); |
| 209 expect(response.stream.bytesToString(), | 209 expect( |
| 210 completion(equals("Hello, world!"))); | 210 response.stream.bytesToString(), completion(equals("Hello, world!"))); |
| 211 }); | 211 }); |
| 212 }); | 212 }); |
| 213 | 213 |
| 214 test('reports an error if a HijackException is thrown without hijacking', () { | 214 test('reports an error if a HijackException is thrown without hijacking', () { |
| 215 _scheduleServer((request) => throw const HijackException()); | 215 _scheduleServer((request) => throw const HijackException()); |
| 216 | 216 |
| 217 return _scheduleGet().then((response) { | 217 return _scheduleGet().then((response) { |
| 218 expect(response.statusCode, HttpStatus.INTERNAL_SERVER_ERROR); | 218 expect(response.statusCode, HttpStatus.INTERNAL_SERVER_ERROR); |
| 219 }); | 219 }); |
| 220 }); | 220 }); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 return server.close(force: true); | 346 return server.close(force: true); |
| 347 }); | 347 }); |
| 348 | 348 |
| 349 _serverPort = server.port; | 349 _serverPort = server.port; |
| 350 })); | 350 })); |
| 351 } | 351 } |
| 352 | 352 |
| 353 Future<http.Response> _scheduleGet({Map<String, String> headers}) { | 353 Future<http.Response> _scheduleGet({Map<String, String> headers}) { |
| 354 if (headers == null) headers = {}; | 354 if (headers == null) headers = {}; |
| 355 | 355 |
| 356 return schedule(() => | 356 return schedule( |
| 357 http.get('http://localhost:$_serverPort/', headers: headers)); | 357 () => http.get('http://localhost:$_serverPort/', headers: headers)); |
| 358 } | 358 } |
| 359 | 359 |
| 360 Future<http.StreamedResponse> _schedulePost({Map<String, String> headers, | 360 Future<http.StreamedResponse> _schedulePost( |
| 361 String body}) { | 361 {Map<String, String> headers, String body}) { |
| 362 | |
| 363 return schedule(() { | 362 return schedule(() { |
| 364 | 363 var request = |
| 365 var request = new http.Request('POST', | 364 new http.Request('POST', Uri.parse('http://localhost:$_serverPort/')); |
| 366 Uri.parse('http://localhost:$_serverPort/')); | |
| 367 | 365 |
| 368 if (headers != null) request.headers.addAll(headers); | 366 if (headers != null) request.headers.addAll(headers); |
| 369 if (body != null) request.body = body; | 367 if (body != null) request.body = body; |
| 370 | 368 |
| 371 return request.send(); | 369 return request.send(); |
| 372 }); | 370 }); |
| 373 } | 371 } |
| OLD | NEW |