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

Unified Diff: pkg/shelf/lib/shelf_io.dart

Issue 300023003: pkg/shelf - send Date header in shelf_io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: only expose option on util method Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/shelf/pubspec.yaml » ('j') | pkg/shelf/test/shelf_io_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/shelf/lib/shelf_io.dart
diff --git a/pkg/shelf/lib/shelf_io.dart b/pkg/shelf/lib/shelf_io.dart
index d8d4d9ca3175e9b0cfea38c36302eeee00bfeb22..98fd319a6873b35ee3d394142e15270d5fb634d8 100644
--- a/pkg/shelf/lib/shelf_io.dart
+++ b/pkg/shelf/lib/shelf_io.dart
@@ -52,7 +52,12 @@ void serveRequests(Stream<HttpRequest> requests, Handler handler) {
/// Uses [handler] to handle [request].
///
/// Returns a [Future] which completes when the request has been handled.
-Future handleRequest(HttpRequest request, Handler handler) {
+///
+/// If [includeDateHeader] is `true`, the `Date` header is included with a value
+/// of `new DateTime.now` at the time the response is written. The default is
+/// `true`.
nweiz 2014/05/27 19:52:44 Why is this configurable? Any configuration that's
kevmoo 2014/05/27 20:50:58 DONE I guess we can always add this later if dema
+Future handleRequest(HttpRequest request, Handler handler,
+ {bool includeDateHeader: true}) {
var shelfRequest = _fromHttpRequest(request);
// TODO(nweiz): abstract out hijack handling to make it easier to implement an
@@ -83,7 +88,7 @@ Future handleRequest(HttpRequest request, Handler handler) {
throw new Exception(message.toString().trim());
}
- return _writeResponse(response, request.response);
+ return _writeResponse(response, request.response, includeDateHeader);
}).catchError((error, stackTrace) {
// Ignore HijackExceptions.
if (error is! HijackException) throw error;
@@ -109,7 +114,8 @@ Request _fromHttpRequest(HttpRequest request) {
body: request, onHijack: onHijack);
}
-Future _writeResponse(Response response, HttpResponse httpResponse) {
+Future _writeResponse(Response response, HttpResponse httpResponse,
+ bool includeDateHeader) {
httpResponse.statusCode = response.statusCode;
response.headers.forEach((header, value) {
@@ -121,6 +127,11 @@ Future _writeResponse(Response response, HttpResponse httpResponse) {
var value = httpResponse.headers.value(HttpHeaders.SERVER);
httpResponse.headers.set(HttpHeaders.SERVER, '$value with Shelf');
}
+
+ if (includeDateHeader && !response.headers.containsKey(HttpHeaders.DATE)) {
+ httpResponse.headers.date = new DateTime.now().toUtc();
+ }
+
return httpResponse.addStream(response.read())
.then((_) => httpResponse.close());
}
« no previous file with comments | « no previous file | pkg/shelf/pubspec.yaml » ('j') | pkg/shelf/test/shelf_io_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698