Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove charset from "Content-Type" header

Now the null value will be reflected for the charset in the header.
  • Loading branch information
jefioliveira committed May 15, 2019
1 parent 8d6213c commit 7358816
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
35 changes: 19 additions & 16 deletions lib/src/base_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,27 @@ abstract class BaseClient implements Client {
if (url is String) url = Uri.parse(url);
var request = new Request(method, url);

if (headers != null) request.headers.addAll(headers);
if(encoding != null) request.encoding = encoding; else {
request.isIgnoreEncoding = true;
}
if (body != null) {
if (body is String) {
request.body = body;
} else if (body is List) {
request.bodyBytes = body.cast<int>();
} else if (body is Map) {
request.bodyFields = body.cast<String, String>();
} else {
throw new ArgumentError('Invalid request body "$body".');
}
if (headers != null) {
request.headers.addAll(headers);
}
if (encoding != null) {
request.encoding = encoding;
} else {
request.isIgnoreEncoding = true;
}
if (body != null) {
if (body is String) {
request.body = body;
} else if (body is List) {
request.bodyBytes = body.cast<int>();
} else if (body is Map) {
request.bodyFields = body.cast<String, String>();
} else {
throw new ArgumentError('Invalid request body "$body".');
}
}

return Response.fromStream(await send(request));

return Response.fromStream(await send(request));
}

/// Throws an error if [response] is not successful.
Expand Down
5 changes: 3 additions & 2 deletions lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ class Request extends BaseRequest {
_defaultEncoding = value;
var contentType = _contentType;
if (contentType == null) return;
if (isIgnoreEncoding)
if (isIgnoreEncoding) {
_contentType = contentType.change(parameters: {});
else
} else {
_contentType = contentType.change(parameters: {'charset': value.name});
}
}

// TODO(nweiz): make this return a read-only view
Expand Down

0 comments on commit 7358816

Please sign in to comment.