Skip to content

Commit 0371a64

Browse files
authored
Changed advertised server technology response header (#258)
was: Server -> dart:io with Self now: X-Powered-By -> Dart with package:shelf Will make it easier to detect pkg:shelf when used on cloud providers, etc
1 parent 9dab944 commit 0371a64

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

pkgs/shelf/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.3.2
2+
3+
* `shelf_io.dart`
4+
* Started setting `X-Powered-By` response header
5+
to `Dart with package:shelf`.
6+
* Stopped setting `Server` header (with value `dart:io with Shelf`).
7+
18
## 1.3.1
29

310
* Update the pubspec `repository` field.

pkgs/shelf/lib/shelf_io.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ Future<void> _writeResponse(Response response, HttpResponse httpResponse) {
217217
httpResponse.headers.set(HttpHeaders.transferEncodingHeader, 'chunked');
218218
}
219219

220-
if (!response.headers.containsKey(HttpHeaders.serverHeader)) {
221-
httpResponse.headers.set(HttpHeaders.serverHeader, 'dart:io with Shelf');
220+
if (!response.headers.containsKey(_xPoweredByResponseHeader)) {
221+
httpResponse.headers
222+
.set(_xPoweredByResponseHeader, 'Dart with package:shelf');
222223
}
223224

224225
if (!response.headers.containsKey(HttpHeaders.dateHeader)) {
@@ -230,6 +231,11 @@ Future<void> _writeResponse(Response response, HttpResponse httpResponse) {
230231
.then((_) => httpResponse.close());
231232
}
232233

234+
/// Common header to advertise the server technology being used.
235+
///
236+
/// See https://webtechsurvey.com/response-header/x-powered-by
237+
const _xPoweredByResponseHeader = 'X-Powered-By';
238+
233239
// TODO(kevmoo) A developer mode is needed to include error info in response
234240
// TODO(kevmoo) Make error output plugable. stderr, logging, etc
235241
Response _logError(Request request, String message, StackTrace stackTrace) {

pkgs/shelf/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: shelf
2-
version: 1.3.1
2+
version: 1.3.2
33
description: >
44
A model for web server middleware that encourages composition and easy reuse.
55
repository: https://github.com/dart-lang/shelf/tree/master/pkgs/shelf

pkgs/shelf/test/shelf_io_test.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,24 +353,25 @@ void main() {
353353
});
354354
});
355355

356-
group('server header', () {
357-
test('defaults to "dart:io with Shelf"', () async {
356+
group('X-Powered-By header', () {
357+
const poweredBy = 'x-powered-by';
358+
test('defaults to "Dart with package:shelf"', () async {
358359
await _scheduleServer(syncHandler);
359360

360361
var response = await _get();
361-
expect(response.headers,
362-
containsPair(HttpHeaders.serverHeader, 'dart:io with Shelf'));
362+
expect(
363+
response.headers,
364+
containsPair(poweredBy, 'Dart with package:shelf'),
365+
);
363366
});
364367

365368
test('defers to header in response', () async {
366369
await _scheduleServer((request) {
367-
return Response.ok('test',
368-
headers: {HttpHeaders.serverHeader: 'myServer'});
370+
return Response.ok('test', headers: {poweredBy: 'myServer'});
369371
});
370372

371373
var response = await _get();
372-
expect(
373-
response.headers, containsPair(HttpHeaders.serverHeader, 'myServer'));
374+
expect(response.headers, containsPair(poweredBy, 'myServer'));
374375
});
375376
});
376377

0 commit comments

Comments
 (0)