Skip to content

Commit

Permalink
Don't alter Content-Type in Request if user explicitly sets it (dart-…
Browse files Browse the repository at this point in the history
  • Loading branch information
EPNW-Eric committed Mar 3, 2023
1 parent 805a147 commit 49ae6a3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkgs/http/lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,17 @@ class Request extends BaseRequest {
/// This is converted to and from [bodyBytes] using [encoding].
///
/// When this is set, if the request does not yet have a `Content-Type`
/// header, one will be added with the type `text/plain`. Then the `charset`
/// parameter of the `Content-Type` header (whether new or pre-existing) will
/// be set to [encoding] if it wasn't already set.
/// header, one will be added with the type `text/plain; charset=<encoding>`,
/// where `<encoding>` is [encoding]. If there is already a `Content-Type`
/// header, it will not be altered, since in this case, it is the users
/// responsibility to correctly set it.
String get body => encoding.decode(bodyBytes);

set body(String value) {
bodyBytes = encoding.encode(value);
var contentType = _contentType;
if (contentType == null) {
_contentType = MediaType('text', 'plain', {'charset': encoding.name});
} else if (!contentType.parameters.containsKey('charset')) {
_contentType = contentType.change(parameters: {'charset': encoding.name});
}
}

Expand Down

0 comments on commit 49ae6a3

Please sign in to comment.