Skip to content

Ignore charset encoding in header #269

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 6 commits into from
Closed
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions lib/src/base_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ abstract class BaseClient implements Client {
if (url is String) url = Uri.parse(url);
var request = Request(method, url);

if (headers != null) request.headers.addAll(headers);
if (encoding != null) request.encoding = encoding;
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;
Expand Down
13 changes: 10 additions & 3 deletions lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'utils.dart';

/// An HTTP request where the entire request body is known in advance.
class Request extends BaseRequest {
bool isIgnoreEncoding = false;

/// The size of the request body, in bytes. This is calculated from
/// [bodyBytes].
///
Expand Down Expand Up @@ -56,7 +58,11 @@ class Request extends BaseRequest {
_defaultEncoding = value;
var contentType = _contentType;
if (contentType == null) return;
_contentType = contentType.change(parameters: {'charset': value.name});
if (isIgnoreEncoding) {
_contentType = contentType.change(parameters: {});
} else {
_contentType = contentType.change(parameters: {'charset': value.name});
}
}

// TODO(nweiz): make this return a read-only view
Expand Down Expand Up @@ -85,8 +91,9 @@ class Request extends BaseRequest {
bodyBytes = encoding.encode(value);
var contentType = _contentType;
if (contentType == null) {
_contentType = MediaType("text", "plain", {'charset': encoding.name});
} else if (!contentType.parameters.containsKey('charset')) {
_contentType = new MediaType("text", "plain", {'charset': encoding.name});
} else if (!contentType.parameters.containsKey('charset') &&
!isIgnoreEncoding) {
_contentType = contentType.change(parameters: {'charset': encoding.name});
}
}
Expand Down