Skip to content

Commit

Permalink
fix(dart_frog): Response.json() overwrites content-type header (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
easazade committed Apr 18, 2023
1 parent 0ee1422 commit 76c3d9d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
.idea
.idea
.vscode/settings.json
3 changes: 2 additions & 1 deletion packages/dart_frog/lib/src/response.dart
Expand Up @@ -55,7 +55,8 @@ class Response {
body: body != null ? jsonEncode(body) : null,
headers: {
...headers,
HttpHeaders.contentTypeHeader: ContentType.json.value,
if (!headers.containsKey(HttpHeaders.contentTypeHeader))
HttpHeaders.contentTypeHeader: ContentType.json.value,
},
);

Expand Down
11 changes: 11 additions & 0 deletions packages/dart_frog/test/src/response_test.dart
Expand Up @@ -184,6 +184,17 @@ void main() {
final response = Response.json();
expect(response.json(), completion(isEmpty));
});

test('has correct content-type when overriden in headers', () {
final headers = <String, String>{
HttpHeaders.contentTypeHeader: ContentType.html.value,
};
final response = Response.json(headers: headers);
expect(
response.headers[HttpHeaders.contentTypeHeader],
equals(ContentType.html.value),
);
});
});
});
}

0 comments on commit 76c3d9d

Please sign in to comment.