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

Side by Side Diff: pkg/shelf/lib/shelf_io.dart

Issue 281353004: pkg/shelf: Fixed logic for setting Server header in `shelf_io` (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: final nits Created 6 years, 6 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 | « pkg/shelf/CHANGELOG.md ('k') | pkg/shelf/pubspec.yaml » ('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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// A Shelf adapter for handling [HttpRequest] objects from `dart:io`. 5 /// A Shelf adapter for handling [HttpRequest] objects from `dart:io`.
6 /// 6 ///
7 /// One can provide an instance of [HttpServer] as the `requests` parameter in 7 /// One can provide an instance of [HttpServer] as the `requests` parameter in
8 /// [serveRequests]. 8 /// [serveRequests].
9 /// 9 ///
10 /// The `dart:io` adapter supports request hijacking; see [Request.hijack]. 10 /// The `dart:io` adapter supports request hijacking; see [Request.hijack].
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 110 }
111 111
112 Future _writeResponse(Response response, HttpResponse httpResponse) { 112 Future _writeResponse(Response response, HttpResponse httpResponse) {
113 httpResponse.statusCode = response.statusCode; 113 httpResponse.statusCode = response.statusCode;
114 114
115 response.headers.forEach((header, value) { 115 response.headers.forEach((header, value) {
116 if (value == null) return; 116 if (value == null) return;
117 httpResponse.headers.set(header, value); 117 httpResponse.headers.set(header, value);
118 }); 118 });
119 119
120 if (response.headers[HttpHeaders.SERVER] == null) { 120 if (!response.headers.containsKey(HttpHeaders.SERVER)) {
121 var value = httpResponse.headers.value(HttpHeaders.SERVER); 121 httpResponse.headers.set(HttpHeaders.SERVER, 'dart:io with Shelf');
122 httpResponse.headers.set(HttpHeaders.SERVER, '$value with Shelf');
123 } 122 }
124 123
125 if (!response.headers.containsKey(HttpHeaders.DATE)) { 124 if (!response.headers.containsKey(HttpHeaders.DATE)) {
126 httpResponse.headers.date = new DateTime.now().toUtc(); 125 httpResponse.headers.date = new DateTime.now().toUtc();
127 } 126 }
128 127
129 return httpResponse.addStream(response.read()) 128 return httpResponse.addStream(response.read())
130 .then((_) => httpResponse.close()); 129 .then((_) => httpResponse.close());
131 } 130 }
132 131
133 // TODO(kevmoo) A developer mode is needed to include error info in response 132 // TODO(kevmoo) A developer mode is needed to include error info in response
134 // TODO(kevmoo) Make error output plugable. stderr, logging, etc 133 // TODO(kevmoo) Make error output plugable. stderr, logging, etc
135 Response _logError(String message, [StackTrace stackTrace]) { 134 Response _logError(String message, [StackTrace stackTrace]) {
136 var chain = new Chain.current(); 135 var chain = new Chain.current();
137 if (stackTrace != null) { 136 if (stackTrace != null) {
138 chain = new Chain.forTrace(stackTrace); 137 chain = new Chain.forTrace(stackTrace);
139 } 138 }
140 chain = chain 139 chain = chain
141 .foldFrames((frame) => frame.isCore || frame.package == 'shelf') 140 .foldFrames((frame) => frame.isCore || frame.package == 'shelf')
142 .terse; 141 .terse;
143 142
144 stderr.writeln('ERROR - ${new DateTime.now()}'); 143 stderr.writeln('ERROR - ${new DateTime.now()}');
145 stderr.writeln(message); 144 stderr.writeln(message);
146 stderr.writeln(chain); 145 stderr.writeln(chain);
147 return new Response.internalServerError(); 146 return new Response.internalServerError();
148 } 147 }
OLDNEW
« no previous file with comments | « pkg/shelf/CHANGELOG.md ('k') | pkg/shelf/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698