Skip to content

Commit b96f163

Browse files
committed
Merge branch 'Pacane/fix-header-content-type-case-comparison'
2 parents d37bee7 + c5477ac commit b96f163

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.6.4+2
2+
3+
* Fix a bug where the `Content-Type` header didn't interact properly with the
4+
`encoding` parameter for `new Request()` and `new Response()` if it wasn't
5+
lowercase.
6+
17
## 0.6.4+1
28

39
* When the `shelf_io` adapter detects an error, print the request context as

lib/src/message.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ Map<String, String> _adjustHeaders(
139139
Map<String, String> headers, Encoding encoding) {
140140
if (headers == null) headers = const {};
141141
if (encoding == null) return headers;
142+
143+
headers = new CaseInsensitiveMap.from(headers);
142144
if (headers['content-type'] == null) {
143145
return addHeader(headers, 'content-type',
144146
'application/octet-stream; charset=${encoding.name}');

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: 0.6.4+1
2+
version: 0.6.4+2
33
author: Dart Team <[email protected]>
44
description: Web Server Middleware for Dart
55
homepage: https://github.com/dart-lang/shelf

test/message_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'dart:async';
88
import 'dart:convert';
99

1010
import 'package:shelf/src/message.dart';
11+
import 'package:shelf/src/response.dart';
1112
import 'package:test/test.dart';
1213

1314
import 'test_util.dart';
@@ -204,6 +205,14 @@ void main() {
204205
}).encoding, equals(LATIN1));
205206
});
206207

208+
test("comes from the content-type charset parameter with a different case",
209+
() {
210+
expect(_createMessage(
211+
headers: {
212+
'Content-Type': 'text/plain; charset=iso-8859-1'
213+
}).encoding, equals(LATIN1));
214+
});
215+
207216
test("defaults to encoding a String as UTF-8", () {
208217
expect(_createMessage(body: "è").read().toList(),
209218
completion(equals([[195, 168]])));
@@ -221,6 +230,14 @@ void main() {
221230
containsPair('content-type', 'text/plain; charset=iso-8859-1'));
222231
});
223232

233+
test("adds an explicit encoding to the content-type with a different case",
234+
() {
235+
var request = _createMessage(
236+
body: "è", encoding: LATIN1, headers: {'Content-Type': 'text/plain'});
237+
expect(request.headers,
238+
containsPair('Content-Type', 'text/plain; charset=iso-8859-1'));
239+
});
240+
224241
test("sets an absent content-type to application/octet-stream in order to "
225242
"set the charset", () {
226243
var request = _createMessage(body: "è", encoding: LATIN1);

0 commit comments

Comments
 (0)