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 /// Helpers for dealing with HTTP. | 5 /// Helpers for dealing with HTTP. |
6 library pub.http; | 6 library pub.http; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:json' as json; | 10 import 'dart:json' as json; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 /// Logs the fact that [response] was received, and information about it. | 127 /// Logs the fact that [response] was received, and information about it. |
128 void _logResponse(http.StreamedResponse response) { | 128 void _logResponse(http.StreamedResponse response) { |
129 // TODO(nweiz): Fork the response stream and log the response body. Be | 129 // TODO(nweiz): Fork the response stream and log the response body. Be |
130 // careful not to log OAuth2 private data, though. | 130 // careful not to log OAuth2 private data, though. |
131 | 131 |
132 var responseLog = new StringBuffer(); | 132 var responseLog = new StringBuffer(); |
133 var request = response.request; | 133 var request = response.request; |
134 var stopwatch = _requestStopwatches.remove(request)..stop(); | 134 var stopwatch = _requestStopwatches.remove(request)..stop(); |
135 responseLog.writeln("HTTP response ${response.statusCode} " | 135 responseLog.writeln("HTTP response ${response.statusCode} " |
136 "${response.reasonPhrase} for ${request.method} ${request.url}"); | 136 "${response.reasonPhrase} for ${request.method} ${request.url}"); |
137 responseLog.write("took ${stopwatch.elapsed}"); | 137 responseLog.writeln("took ${stopwatch.elapsed}"); |
138 response.headers.forEach((name, value) => | 138 response.headers.forEach((name, value) => |
139 responseLog.writeln(_logField(name, value))); | 139 responseLog.writeln(_logField(name, value))); |
140 | 140 |
141 log.fine(responseLog.toString().trim()); | 141 log.fine(responseLog.toString().trim()); |
142 } | 142 } |
143 | 143 |
144 /// Returns a log-formatted string for the HTTP field or header with the given | 144 /// Returns a log-formatted string for the HTTP field or header with the given |
145 /// [name] and [value]. | 145 /// [name] and [value]. |
146 String _logField(String name, String value) { | 146 String _logField(String name, String value) { |
147 if (_CENSORED_FIELDS.contains(name.toLowerCase())) { | 147 if (_CENSORED_FIELDS.contains(name.toLowerCase())) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 /// Exception thrown when an HTTP operation fails. | 206 /// Exception thrown when an HTTP operation fails. |
207 class PubHttpException implements Exception { | 207 class PubHttpException implements Exception { |
208 final http.Response response; | 208 final http.Response response; |
209 | 209 |
210 const PubHttpException(this.response); | 210 const PubHttpException(this.response); |
211 | 211 |
212 String toString() => 'HTTP error ${response.statusCode}: ' | 212 String toString() => 'HTTP error ${response.statusCode}: ' |
213 '${response.reasonPhrase}'; | 213 '${response.reasonPhrase}'; |
214 } | 214 } |
OLD | NEW |