pkg/shelf: Fixed logic for setting Server header in `shelf_io`
BUG= https://code.google.com/p/dart/issues/detail?id=18737
R=nweiz@google.com
Review URL: https://codereview.chromium.org//281353004
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/shelf@36725 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0588275..538153e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
* The `shelf_io` adapter now sends the `Date` HTTP header by default.
+* Fixed logic for setting Server header in `shelf_io`.
+
## 0.5.3
* Add new named parameters to `Request.change`: `scriptName` and `url`.
diff --git a/lib/shelf_io.dart b/lib/shelf_io.dart
index 6582e5a..c685302 100644
--- a/lib/shelf_io.dart
+++ b/lib/shelf_io.dart
@@ -117,9 +117,8 @@
httpResponse.headers.set(header, value);
});
- if (response.headers[HttpHeaders.SERVER] == null) {
- var value = httpResponse.headers.value(HttpHeaders.SERVER);
- httpResponse.headers.set(HttpHeaders.SERVER, '$value with Shelf');
+ if (!response.headers.containsKey(HttpHeaders.SERVER)) {
+ httpResponse.headers.set(HttpHeaders.SERVER, 'dart:io with Shelf');
}
if (!response.headers.containsKey(HttpHeaders.DATE)) {
diff --git a/pubspec.yaml b/pubspec.yaml
index 548fe38..712ad4a 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: shelf
-version: 0.5.4-dev
+version: 0.5.4
author: Dart Team <misc@dartlang.org>
description: Web Server Middleware for Dart
homepage: http://www.dartlang.org
diff --git a/test/shelf_io_test.dart b/test/shelf_io_test.dart
index c7d9f7a..b3b4325 100644
--- a/test/shelf_io_test.dart
+++ b/test/shelf_io_test.dart
@@ -284,6 +284,28 @@
});
});
});
+
+ group('server header', () {
+ test('defaults to "dart:io with Shelf"', () {
+ _scheduleServer(syncHandler);
+
+ return _scheduleGet().then((response) {
+ expect(response.headers,
+ containsPair(HttpHeaders.SERVER, 'dart:io with Shelf'));
+ });
+ });
+
+ test('defers to header in response', () {
+ _scheduleServer((request) {
+ return new Response.ok('test',
+ headers: {HttpHeaders.SERVER: 'myServer'});
+ });
+
+ return _scheduleGet().then((response) {
+ expect(response.headers, containsPair(HttpHeaders.SERVER, 'myServer'));
+ });
+ });
+ });
}
int _serverPort;