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

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

Issue 12870003: Make argument to StringSink.writeln optional. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fix. 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 | « sdk/lib/io/io_sink.dart ('k') | utils/pub/safe_http_server.dart » ('j') | 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (request is http.MultipartRequest) { 93 if (request is http.MultipartRequest) {
94 requestLog.writeln(''); 94 requestLog.writeln();
95 requestLog.writeln("Body fields:"); 95 requestLog.writeln("Body fields:");
96 request.fields.forEach((name, value) => 96 request.fields.forEach((name, value) =>
97 requestLog.writeln(_logField(name, value))); 97 requestLog.writeln(_logField(name, value)));
98 98
99 // 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) { 100 } else if (request is http.Request) {
101 if (contentType.value == 'application/x-www-form-urlencoded') { 101 if (contentType.value == 'application/x-www-form-urlencoded') {
102 requestLog.writeln(''); 102 requestLog.writeln();
103 requestLog.writeln("Body fields:"); 103 requestLog.writeln("Body fields:");
104 request.bodyFields.forEach((name, value) => 104 request.bodyFields.forEach((name, value) =>
105 requestLog.writeln(_logField(name, value))); 105 requestLog.writeln(_logField(name, value)));
106 } else if (contentType.value == 'text/plain' || 106 } else if (contentType.value == 'text/plain' ||
107 contentType.value == 'application/json') { 107 contentType.value == 'application/json') {
108 requestLog.write(request.body); 108 requestLog.write(request.body);
109 } 109 }
110 } 110 }
111 } 111 }
112 112
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 /// Exception thrown when an HTTP operation fails. 194 /// Exception thrown when an HTTP operation fails.
195 class PubHttpException implements Exception { 195 class PubHttpException implements Exception {
196 final http.Response response; 196 final http.Response response;
197 197
198 const PubHttpException(this.response); 198 const PubHttpException(this.response);
199 199
200 String toString() => 'HTTP error ${response.statusCode}: ' 200 String toString() => 'HTTP error ${response.statusCode}: '
201 '${response.reasonPhrase}'; 201 '${response.reasonPhrase}';
202 } 202 }
OLDNEW
« no previous file with comments | « sdk/lib/io/io_sink.dart ('k') | utils/pub/safe_http_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698