Skip to content

Don't alter Content-Type in Request if user explicitly sets it (#184) #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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