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 // Corelib 'print' implementation. | 8 // Corelib 'print' implementation. |
9 void _print(arg) { | 9 void _print(arg) { |
10 _Logger._printString(arg.toString()); | 10 _Logger._printString(arg.toString()); |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 | 29 |
30 var _httpRequestResponseCode = 0; | 30 var _httpRequestResponseCode = 0; |
31 var _httpRequestStatusString; | 31 var _httpRequestStatusString; |
32 var _httpRequestResponse; | 32 var _httpRequestResponse; |
33 | 33 |
34 _getHttpRequestResponseCode() => _httpRequestResponseCode; | 34 _getHttpRequestResponseCode() => _httpRequestResponseCode; |
35 _getHttpRequestStatusString() => _httpRequestStatusString; | 35 _getHttpRequestStatusString() => _httpRequestStatusString; |
36 _getHttpRequestResponse() => _httpRequestResponse; | 36 _getHttpRequestResponse() => _httpRequestResponse; |
37 | 37 |
38 void _requestCompleted(HttpClientResponseBody body) { | 38 void _requestCompleted(List<int> data, HttpClientResponse response) { |
39 _httpRequestResponseCode = body.statusCode; | 39 _httpRequestResponseCode = response.statusCode; |
40 _httpRequestStatusString = '${body.statusCode} ${body.reasonPhrase}'; | 40 _httpRequestStatusString = '${response.statusCode} ${response.reasonPhrase}'; |
41 _httpRequestResponse = null; | 41 _httpRequestResponse = null; |
42 if (body.statusCode != 200 || body.type == 'json') { | 42 if (response.statusCode != 200 || |
| 43 (response.headers.contentType != null && |
| 44 response.headers.contentType.mimeType == 'application/json')) { |
43 return; | 45 return; |
44 } | 46 } |
45 _httpRequestResponse = body.body; | 47 _httpRequestResponse = data; |
46 } | 48 } |
47 | 49 |
48 | 50 |
49 void _requestFailed(error) { | 51 void _requestFailed(error) { |
50 _httpRequestResponseCode = 0; | 52 _httpRequestResponseCode = 0; |
51 _httpRequestStatusString = error.toString(); | 53 _httpRequestStatusString = error.toString(); |
52 _httpRequestResponse = null; | 54 _httpRequestResponse = null; |
53 } | 55 } |
54 | 56 |
55 | 57 |
56 void _makeHttpRequest(String uri) { | 58 void _makeHttpRequest(String uri) { |
57 var _client = new HttpClient(); | 59 var _client = new HttpClient(); |
58 _httpRequestResponseCode = 0; | 60 _httpRequestResponseCode = 0; |
59 _httpRequestStatusString = null; | 61 _httpRequestStatusString = null; |
60 _httpRequestResponse = null; | 62 _httpRequestResponse = null; |
61 Uri requestUri = Uri.parse(uri); | 63 Uri requestUri = Uri.parse(uri); |
62 _client.getUrl(requestUri) | 64 _client.getUrl(requestUri) |
63 .then((HttpClientRequest request) => request.close()) | 65 .then((HttpClientRequest request) => request.close()) |
64 .then(HttpBodyHandler.processResponse) | 66 .then((HttpClientResponse response) { |
65 .then((HttpClientResponseBody body) { | 67 return response |
66 _requestCompleted(body); | 68 .fold(new BytesBuilder(), (b, d) => b..add(d)) |
| 69 .then((builder) { |
| 70 _requestCompleted(builder.takeBytes(), response); |
| 71 }); |
67 }).catchError((error) { | 72 }).catchError((error) { |
68 _requestFailed(error); | 73 _requestFailed(error); |
69 }); | 74 }); |
70 } | 75 } |
71 | 76 |
72 | 77 |
73 // Are we running on Windows? | 78 // Are we running on Windows? |
74 var _isWindows = false; | 79 var _isWindows = false; |
75 // The current working directory | 80 // The current working directory |
76 var _workingDirectoryUri; | 81 var _workingDirectoryUri; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 269 } |
265 _logResolution('# Package: $uri -> $path'); | 270 _logResolution('# Package: $uri -> $path'); |
266 return path; | 271 return path; |
267 } | 272 } |
268 | 273 |
269 | 274 |
270 String _filePathFromHttpUri(Uri uri) { | 275 String _filePathFromHttpUri(Uri uri) { |
271 _logResolution('# Path: $uri -> $uri'); | 276 _logResolution('# Path: $uri -> $uri'); |
272 return uri.toString(); | 277 return uri.toString(); |
273 } | 278 } |
OLD | NEW |