Skip to content

Commit 76c3d9d

Browse files
authored
fix(dart_frog): Response.json() overwrites content-type header (#596)
1 parent 0ee1422 commit 76c3d9d

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea
1+
.idea
2+
.vscode/settings.json

packages/dart_frog/lib/src/response.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class Response {
5555
body: body != null ? jsonEncode(body) : null,
5656
headers: {
5757
...headers,
58-
HttpHeaders.contentTypeHeader: ContentType.json.value,
58+
if (!headers.containsKey(HttpHeaders.contentTypeHeader))
59+
HttpHeaders.contentTypeHeader: ContentType.json.value,
5960
},
6061
);
6162

packages/dart_frog/test/src/response_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ void main() {
184184
final response = Response.json();
185185
expect(response.json(), completion(isEmpty));
186186
});
187+
188+
test('has correct content-type when overriden in headers', () {
189+
final headers = <String, String>{
190+
HttpHeaders.contentTypeHeader: ContentType.html.value,
191+
};
192+
final response = Response.json(headers: headers);
193+
expect(
194+
response.headers[HttpHeaders.contentTypeHeader],
195+
equals(ContentType.html.value),
196+
);
197+
});
187198
});
188199
});
189200
}

0 commit comments

Comments
 (0)