From eeca0e53063298faf506eb0e238b6dfbb25b64ea Mon Sep 17 00:00:00 2001 From: jefioliveira Date: Fri, 22 Feb 2019 20:40:33 -0300 Subject: [PATCH 1/5] #184 Remove charset from "Content-Type" header Now the null value will be reflected for the charset in the header. --- lib/src/base_client.dart | 25 +++++++++++++------------ lib/src/request.dart | 5 ++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/src/base_client.dart b/lib/src/base_client.dart index 2a1f246dda..da68cc84e7 100644 --- a/lib/src/base_client.dart +++ b/lib/src/base_client.dart @@ -153,20 +153,21 @@ abstract class BaseClient implements Client { var request = new Request(method, url); if (headers != null) request.headers.addAll(headers); - if (encoding != null) request.encoding = encoding; - if (body != null) { - if (body is String) { - request.body = body; - } else if (body is List) { - request.bodyBytes = body.cast(); - } else if (body is Map) { - request.bodyFields = body.cast(); - } else { - throw new ArgumentError('Invalid request body "$body".'); + request.encoding = encoding; + if (body != null) { + if (body is String) { + request.body = body; + } else if (body is List) { + request.bodyBytes = body.cast(); + } else if (body is Map) { + request.bodyFields = body.cast(); + } 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. diff --git a/lib/src/request.dart b/lib/src/request.dart index 8c638b18fc..7b9006a14f 100644 --- a/lib/src/request.dart +++ b/lib/src/request.dart @@ -56,7 +56,10 @@ class Request extends BaseRequest { _defaultEncoding = value; var contentType = _contentType; if (contentType == null) return; - _contentType = contentType.change(parameters: {'charset': value.name}); + if (value == null) + _contentType = contentType.change(parameters: {}); + else + _contentType = contentType.change(parameters: {'charset': value.name}); } // TODO(nweiz): make this return a read-only view From da0d7fce846536e51af2e5a4bfdd9b015f6bf75d Mon Sep 17 00:00:00 2001 From: jefioliveira Date: Fri, 22 Feb 2019 22:01:37 -0300 Subject: [PATCH 2/5] #184 Remove charset from "Content-Type" header Now the null value will be reflected for the charset in the header. --- lib/src/request.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/request.dart b/lib/src/request.dart index 7b9006a14f..98b5afcf73 100644 --- a/lib/src/request.dart +++ b/lib/src/request.dart @@ -89,7 +89,8 @@ class Request extends BaseRequest { var contentType = _contentType; if (contentType == null) { _contentType = new MediaType("text", "plain", {'charset': encoding.name}); - } else if (!contentType.parameters.containsKey('charset')) { + } else if (!contentType.parameters.containsKey('charset') && encoding != + null) { _contentType = contentType.change(parameters: {'charset': encoding.name}); } } From 72b80672f158719c58adec80ead5f0752f2ea7a4 Mon Sep 17 00:00:00 2001 From: jefioliveira Date: Fri, 22 Feb 2019 22:21:26 -0300 Subject: [PATCH 3/5] #184 Remove charset from "Content-Type" header Now the null value will be reflected for the charset in the header. --- lib/src/base_client.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/base_client.dart b/lib/src/base_client.dart index da68cc84e7..67ca149596 100644 --- a/lib/src/base_client.dart +++ b/lib/src/base_client.dart @@ -152,8 +152,7 @@ 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); - request.encoding = encoding; + if (body != null) { if (body is String) { request.body = body; @@ -165,7 +164,8 @@ abstract class BaseClient implements Client { throw new ArgumentError('Invalid request body "$body".'); } } - + if (headers != null) request.headers.addAll(headers); + request.encoding = encoding; return Response.fromStream(await send(request)); } From 8d6213cac32856c3fec6a0d01504ce0b9abb96cb Mon Sep 17 00:00:00 2001 From: jefioliveira Date: Fri, 22 Feb 2019 22:37:52 -0300 Subject: [PATCH 4/5] #184 Remove charset from "Content-Type" header Now the null value will be reflected for the charset in the header. --- lib/src/base_client.dart | 8 +++++--- lib/src/request.dart | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/src/base_client.dart b/lib/src/base_client.dart index 67ca149596..3cc631f534 100644 --- a/lib/src/base_client.dart +++ b/lib/src/base_client.dart @@ -152,7 +152,10 @@ 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; @@ -164,8 +167,7 @@ abstract class BaseClient implements Client { throw new ArgumentError('Invalid request body "$body".'); } } - if (headers != null) request.headers.addAll(headers); - request.encoding = encoding; + return Response.fromStream(await send(request)); } diff --git a/lib/src/request.dart b/lib/src/request.dart index 98b5afcf73..5bd52f86b7 100644 --- a/lib/src/request.dart +++ b/lib/src/request.dart @@ -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]. /// @@ -56,7 +58,7 @@ class Request extends BaseRequest { _defaultEncoding = value; var contentType = _contentType; if (contentType == null) return; - if (value == null) + if (isIgnoreEncoding) _contentType = contentType.change(parameters: {}); else _contentType = contentType.change(parameters: {'charset': value.name}); @@ -89,8 +91,8 @@ class Request extends BaseRequest { var contentType = _contentType; if (contentType == null) { _contentType = new MediaType("text", "plain", {'charset': encoding.name}); - } else if (!contentType.parameters.containsKey('charset') && encoding != - null) { + } else if (!contentType.parameters.containsKey('charset') && + !isIgnoreEncoding) { _contentType = contentType.change(parameters: {'charset': encoding.name}); } } From 7358816926a99e633bb220d75bc71ccf495b7353 Mon Sep 17 00:00:00 2001 From: jefioliveira Date: Wed, 15 May 2019 00:20:33 -0300 Subject: [PATCH 5/5] #184 Remove charset from "Content-Type" header Now the null value will be reflected for the charset in the header. --- lib/src/base_client.dart | 35 +++++++++++++++++++---------------- lib/src/request.dart | 5 +++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/src/base_client.dart b/lib/src/base_client.dart index 3cc631f534..3cb867c505 100644 --- a/lib/src/base_client.dart +++ b/lib/src/base_client.dart @@ -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(); - } else if (body is Map) { - request.bodyFields = body.cast(); - } 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(); + } else if (body is Map) { + request.bodyFields = body.cast(); + } 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. diff --git a/lib/src/request.dart b/lib/src/request.dart index 5bd52f86b7..41da849e08 100644 --- a/lib/src/request.dart +++ b/lib/src/request.dart @@ -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