Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: utils/pub/http.dart

Issue 12820009: Fix some analyzer warnings in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void _logRequest(http.BaseRequest request) { 83 void _logRequest(http.BaseRequest request) {
84 var requestLog = new StringBuffer(); 84 var requestLog = new StringBuffer();
85 requestLog.writeln("HTTP ${request.method} ${request.url}"); 85 requestLog.writeln("HTTP ${request.method} ${request.url}");
86 request.headers.forEach((name, value) => 86 request.headers.forEach((name, value) =>
87 requestLog.writeln(_logField(name, value))); 87 requestLog.writeln(_logField(name, value)));
88 88
89 if (request.method == 'POST') { 89 if (request.method == 'POST') {
90 var contentTypeString = request.headers[HttpHeaders.CONTENT_TYPE]; 90 var contentTypeString = request.headers[HttpHeaders.CONTENT_TYPE];
91 if (contentTypeString == null) contentTypeString = ''; 91 if (contentTypeString == null) contentTypeString = '';
92 var contentType = new ContentType.fromString(contentTypeString); 92 var contentType = new ContentType.fromString(contentTypeString);
93 if (contentType.value == 'application/x-www-form-urlencoded') { 93 if (request is http.MultipartRequest) {
94 requestLog.writeln('');
95 requestLog.writeln("Body fields:");
96 request.bodyFields.forEach((name, value) =>
97 requestLog.writeln(_logField(name, value)));
98 } else if (contentType.value == 'text/plain' ||
99 contentType.value == 'application/json') {
100 requestLog.write(request.body);
101 } else if (request is http.MultipartRequest) {
102 requestLog.writeln(''); 94 requestLog.writeln('');
103 requestLog.writeln("Body fields:"); 95 requestLog.writeln("Body fields:");
104 request.fields.forEach((name, value) => 96 request.fields.forEach((name, value) =>
105 requestLog.writeln(_logField(name, value))); 97 requestLog.writeln(_logField(name, value)));
106 98
107 // TODO(nweiz): make MultipartRequest.files readable, and log them? 99 // TODO(nweiz): make MultipartRequest.files readable, and log them?
100 } else if (request is http.Request) {
101 if (contentType.value == 'application/x-www-form-urlencoded') {
102 requestLog.writeln('');
103 requestLog.writeln("Body fields:");
104 request.bodyFields.forEach((name, value) =>
105 requestLog.writeln(_logField(name, value)));
106 } else if (contentType.value == 'text/plain' ||
107 contentType.value == 'application/json') {
108 requestLog.write(request.body);
109 }
108 } 110 }
109 } 111 }
110 112
111 log.fine(requestLog.toString().trim()); 113 log.fine(requestLog.toString().trim());
112 } 114 }
113 115
114 /// Logs the fact that [response] was received, and information about it. 116 /// Logs the fact that [response] was received, and information about it.
115 void _logResponse(http.StreamedResponse response) { 117 void _logResponse(http.StreamedResponse response) {
116 // TODO(nweiz): Fork the response stream and log the response body. Be 118 // TODO(nweiz): Fork the response stream and log the response body. Be
117 // careful not to log OAuth2 private data, though. 119 // careful not to log OAuth2 private data, though.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 193
192 /// Exception thrown when an HTTP operation fails. 194 /// Exception thrown when an HTTP operation fails.
193 class PubHttpException implements Exception { 195 class PubHttpException implements Exception {
194 final http.Response response; 196 final http.Response response;
195 197
196 const PubHttpException(this.response); 198 const PubHttpException(this.response);
197 199
198 String toString() => 'HTTP error ${response.statusCode}: ' 200 String toString() => 'HTTP error ${response.statusCode}: '
199 '${response.reasonPhrase}'; 201 '${response.reasonPhrase}';
200 } 202 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698