Chromium Code Reviews| 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 builtin; | 5 library builtin; |
| 6 import 'dart:io'; | |
|
siva
2013/05/31 21:02:02
I hope we won't get into any bootstrapping issues
| |
| 7 | |
| 8 int _httpRequestResponseCode = 0; | |
| 9 String _httpRequestStatusString; | |
| 10 List<int> _httpRequestResponse; | |
| 11 | |
| 12 void _requestCompleted(HttpClientResponse response, List<int> responseData) { | |
| 13 _httpRequestResponseCode = response.statusCode; | |
| 14 _httpRequestStatusString = '${response.statusCode} ${response.reasonPhrase}'; | |
| 15 _httpRequestResponse = responseData; | |
| 16 } | |
| 17 | |
| 18 void _requestFailed(error) { | |
| 19 _httpRequestResponseCode = 0; | |
| 20 _httpRequestStatusString = error.toString(); | |
| 21 _httpRequestResponse = null; | |
| 22 } | |
| 23 | |
| 24 HttpClient _client = new HttpClient(); | |
| 25 void _makeHttpRequest(String uri) { | |
| 26 _httpRequestResponseCode = 0; | |
| 27 _httpRequestStatusString = null; | |
| 28 _httpRequestResponse = null; | |
| 29 | |
| 30 Uri requestUri = Uri.parse(uri); | |
| 31 | |
| 32 _client.getUrl(requestUri).then((HttpClientRequest request) { | |
| 33 return request.close(); | |
| 34 }).then((HttpClientResponse response) { | |
| 35 response.listen((List<int> responseData) { | |
| 36 _requestCompleted(response, responseData); | |
| 37 }); | |
| 38 }).catchError((error) { | |
| 39 _requestFailed(error); | |
| 40 }); | |
| 41 } | |
| 6 | 42 |
| 7 // Corelib 'print' implementation. | 43 // Corelib 'print' implementation. |
| 8 void _print(arg) { | 44 void _print(arg) { |
| 9 _Logger._printString(arg.toString()); | 45 _Logger._printString(arg.toString()); |
| 10 } | 46 } |
| 11 | 47 |
| 12 class _Logger { | 48 class _Logger { |
| 13 static void _printString(String s) native "Logger_PrintString"; | 49 static void _printString(String s) native "Logger_PrintString"; |
| 14 } | 50 } |
| 15 | 51 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 return uri.toString(); | 207 return uri.toString(); |
| 172 } | 208 } |
| 173 | 209 |
| 174 String _pathFromHttpUri(String userUri) { | 210 String _pathFromHttpUri(String userUri) { |
| 175 var uri = Uri.parse(userUri); | 211 var uri = Uri.parse(userUri); |
| 176 return uri.path; | 212 return uri.path; |
| 177 } | 213 } |
| 178 | 214 |
| 179 String _domainFromHttpUri(String userUri) { | 215 String _domainFromHttpUri(String userUri) { |
| 180 var uri = Uri.parse(userUri); | 216 var uri = Uri.parse(userUri); |
| 181 return uri.domain; | 217 return uri.host; |
| 182 } | 218 } |
| 183 | 219 |
| 184 int _portFromHttpUri(String userUri) { | 220 int _portFromHttpUri(String userUri) { |
| 185 var uri = Uri.parse(userUri); | 221 var uri = Uri.parse(userUri); |
| 186 return uri.port == 0 ? 80 : uri.port; | 222 return uri.port == 0 ? 80 : uri.port; |
| 187 } | 223 } |
| OLD | NEW |