| OLD | NEW |
| 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 library curl_client_test; | 5 library curl_client_test; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
| 9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 /// Converts [bytes] into a [String] according to [encoding]. | 45 /// Converts [bytes] into a [String] according to [encoding]. |
| 46 String decodeString(List<int> bytes, Encoding encoding) { | 46 String decodeString(List<int> bytes, Encoding encoding) { |
| 47 // TODO(nweiz): implement this once issue 6284 is fixed. | 47 // TODO(nweiz): implement this once issue 6284 is fixed. |
| 48 return new String.fromCharCodes(bytes); | 48 return new String.fromCharCodes(bytes); |
| 49 } | 49 } |
| 50 | 50 |
| 51 /// The current server instance. | 51 /// The current server instance. |
| 52 HttpServer _server; | 52 HttpServer _server; |
| 53 | 53 |
| 54 /// The URL for the current server instance. | 54 /// The URL for the current server instance. |
| 55 Uri get serverUrl => new Uri.fromString('http://localhost:${_server.port}'); | 55 Uri get serverUrl => Uri.parse('http://localhost:${_server.port}'); |
| 56 | 56 |
| 57 /// A dummy URL for constructing requests that won't be sent. | 57 /// A dummy URL for constructing requests that won't be sent. |
| 58 Uri get dummyUrl => new Uri.fromString('http://dartlang.org/'); | 58 Uri get dummyUrl => Uri.parse('http://dartlang.org/'); |
| 59 | 59 |
| 60 /// Starts a new HTTP server. | 60 /// Starts a new HTTP server. |
| 61 void startServer() { | 61 void startServer() { |
| 62 _server = new HttpServer(); | 62 _server = new HttpServer(); |
| 63 | 63 |
| 64 _server.addRequestHandler((request) => request.path == '/error', | 64 _server.addRequestHandler((request) => request.path == '/error', |
| 65 (request, response) { | 65 (request, response) { |
| 66 response.statusCode = 400; | 66 response.statusCode = 400; |
| 67 response.contentLength = 0; | 67 response.contentLength = 0; |
| 68 response.outputStream.close(); | 68 response.outputStream.close(); |
| 69 }); | 69 }); |
| 70 | 70 |
| 71 _server.addRequestHandler((request) => request.path == '/loop', | 71 _server.addRequestHandler((request) => request.path == '/loop', |
| 72 (request, response) { | 72 (request, response) { |
| 73 var n = int.parse(new Uri.fromString(request.uri).query); | 73 var n = int.parse(Uri.parse(request.uri).query); |
| 74 response.statusCode = 302; | 74 response.statusCode = 302; |
| 75 response.headers.set('location', | 75 response.headers.set('location', |
| 76 serverUrl.resolve('/loop?${n + 1}').toString()); | 76 serverUrl.resolve('/loop?${n + 1}').toString()); |
| 77 response.contentLength = 0; | 77 response.contentLength = 0; |
| 78 response.outputStream.close(); | 78 response.outputStream.close(); |
| 79 }); | 79 }); |
| 80 | 80 |
| 81 _server.addRequestHandler((request) => request.path == '/redirect', | 81 _server.addRequestHandler((request) => request.path == '/redirect', |
| 82 (request, response) { | 82 (request, response) { |
| 83 response.statusCode = 302; | 83 response.statusCode = 302; |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 test('without following redirects', () { | 451 test('without following redirects', () { |
| 452 var request = new http.Request('GET', serverUrl.resolve('/redirect')); | 452 var request = new http.Request('GET', serverUrl.resolve('/redirect')); |
| 453 request.followRedirects = false; | 453 request.followRedirects = false; |
| 454 expect(new CurlClient().send(request).then(http.Response.fromStream) | 454 expect(new CurlClient().send(request).then(http.Response.fromStream) |
| 455 .then((response) { | 455 .then((response) { |
| 456 expect(response.statusCode, equals(302)); | 456 expect(response.statusCode, equals(302)); |
| 457 expect(response.isRedirect, true); | 457 expect(response.isRedirect, true); |
| 458 }), completes); | 458 }), completes); |
| 459 }); | 459 }); |
| 460 } | 460 } |
| OLD | NEW |