| 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'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 int _httpRequestResponseCode = 0; | 8 int _httpRequestResponseCode = 0; |
| 9 String _httpRequestStatusString; | 9 String _httpRequestStatusString; |
| 10 List<int> _httpRequestResponse; | 10 var _httpRequestResponse; |
| 11 | 11 |
| 12 void _requestCompleted(HttpClientResponse response, List<int> responseData) { | 12 void _requestCompleted(HttpClientResponseBody body) { |
| 13 _httpRequestResponseCode = response.statusCode; | 13 _httpRequestResponseCode = body.statusCode; |
| 14 _httpRequestStatusString = '${response.statusCode} ${response.reasonPhrase}'; | 14 _httpRequestStatusString = '${body.statusCode} ${body.reasonPhrase}'; |
| 15 _httpRequestResponse = responseData; | 15 _httpRequestResponse = null; |
| 16 if (body.statusCode != 200 || body.type == "json") { |
| 17 return; |
| 18 } |
| 19 _httpRequestResponse = body.body; |
| 16 } | 20 } |
| 17 | 21 |
| 18 void _requestFailed(error) { | 22 void _requestFailed(error) { |
| 19 _httpRequestResponseCode = 0; | 23 _httpRequestResponseCode = 0; |
| 20 _httpRequestStatusString = error.toString(); | 24 _httpRequestStatusString = error.toString(); |
| 21 _httpRequestResponse = null; | 25 _httpRequestResponse = null; |
| 22 } | 26 } |
| 23 | 27 |
| 24 HttpClient _client = new HttpClient(); | 28 HttpClient _client = new HttpClient(); |
| 25 void _makeHttpRequest(String uri) { | 29 void _makeHttpRequest(String uri) { |
| 26 _httpRequestResponseCode = 0; | 30 _httpRequestResponseCode = 0; |
| 27 _httpRequestStatusString = null; | 31 _httpRequestStatusString = null; |
| 28 _httpRequestResponse = null; | 32 _httpRequestResponse = null; |
| 29 | |
| 30 Uri requestUri = Uri.parse(uri); | 33 Uri requestUri = Uri.parse(uri); |
| 31 | 34 _client.getUrl(requestUri) |
| 32 _client.getUrl(requestUri).then((HttpClientRequest request) { | 35 .then((HttpClientRequest request) => request.close()) |
| 33 return request.close(); | 36 .then(HttpBodyHandler.processResponse) |
| 34 }).then((HttpClientResponse response) { | 37 .then((HttpClientResponseBody body) { |
| 35 response.listen((List<int> responseData) { | 38 _requestCompleted(body); |
| 36 _requestCompleted(response, responseData); | 39 }).catchError((error) { |
| 37 }); | 40 _requestFailed(error); |
| 38 }).catchError((error) { | 41 }); |
| 39 _requestFailed(error); | |
| 40 }); | |
| 41 } | 42 } |
| 42 | 43 |
| 43 // Corelib 'print' implementation. | 44 // Corelib 'print' implementation. |
| 44 void _print(arg) { | 45 void _print(arg) { |
| 45 _Logger._printString(arg.toString()); | 46 _Logger._printString(arg.toString()); |
| 46 } | 47 } |
| 47 | 48 |
| 48 class _Logger { | 49 class _Logger { |
| 49 static void _printString(String s) native "Logger_PrintString"; | 50 static void _printString(String s) native "Logger_PrintString"; |
| 50 } | 51 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 200 } |
| 200 | 201 |
| 201 _logResolution("# Package: $path"); | 202 _logResolution("# Package: $path"); |
| 202 return path; | 203 return path; |
| 203 } | 204 } |
| 204 | 205 |
| 205 String _filePathFromHttpUri(Uri uri) { | 206 String _filePathFromHttpUri(Uri uri) { |
| 206 _logResolution('# Path: $uri'); | 207 _logResolution('# Path: $uri'); |
| 207 return uri.toString(); | 208 return uri.toString(); |
| 208 } | 209 } |
| OLD | NEW |