@@ -189,23 +189,12 @@ void main() {
189189 expect (request.headers, containsPair ('content-type' , 'application/json' ));
190190 });
191191
192- test (
193- 'is set to application/x-www-form-urlencoded with charset utf-8 if '
194- 'bodyFields is set' , () {
195- var request = http.Request ('POST' , dummyUrl)
196- ..bodyFields = {'hello' : 'world' };
197- expect (request.headers['Content-Type' ],
198- equals ('application/x-www-form-urlencoded; charset=utf-8' ));
199- });
200-
201- test (
202- 'is set to application/x-www-form-urlencoded with the given charset '
203- 'if bodyFields and encoding are set' , () {
192+ test ('is set to application/x-www-form-urlencoded if bodyFields is set' ,
193+ () {
204194 var request = http.Request ('POST' , dummyUrl)
205- ..encoding = latin1
206195 ..bodyFields = {'hello' : 'world' };
207196 expect (request.headers['Content-Type' ],
208- equals ('application/x-www-form-urlencoded; charset=iso-8859-1 ' ));
197+ equals ('application/x-www-form-urlencoded' ));
209198 });
210199
211200 test (
@@ -218,20 +207,66 @@ void main() {
218207 equals ('text/plain; charset=iso-8859-1' ));
219208 });
220209
221- test ('is modified to include utf-8 if body is set' , () {
210+ test ('is modified to include utf-8 if body is set and mime type is text' ,
211+ () {
212+ var request = http.Request ('POST' , dummyUrl);
213+ request.headers['Content-Type' ] = 'text/plain' ;
214+ request.body = 'Hello World!' ;
215+ expect (
216+ request.headers['Content-Type' ], equals ('text/plain; charset=utf-8' ));
217+ });
218+
219+ test ('is modified to include utf-8 if body is set and mime type is xml' ,
220+ () {
221+ var request = http.Request ('POST' , dummyUrl);
222+ request.headers['Content-Type' ] = 'application/xml' ;
223+ request.body = '<?xml...' ;
224+ expect (request.headers['Content-Type' ],
225+ equals ('application/xml; charset=utf-8' ));
226+ });
227+
228+ test (
229+ 'is not modified to include utf-8 if body is set and mime type is json' ,
230+ () {
222231 var request = http.Request ('POST' , dummyUrl);
223232 request.headers['Content-Type' ] = 'application/json' ;
224233 request.body = '{"hello": "world"}' ;
234+ expect (request.headers['Content-Type' ], equals ('application/json' ));
235+ });
236+
237+ test (
238+ 'is modified to include the given encoding if encoding is set and '
239+ 'mime type is text' , () {
240+ var request = http.Request ('POST' , dummyUrl);
241+ request.headers['Content-Type' ] = 'text/plain' ;
242+ request
243+ ..body = 'Hello World!'
244+ ..encoding = latin1;
245+ expect (request.headers['Content-Type' ],
246+ equals ('text/plain; charset=iso-8859-1' ));
247+ });
248+
249+ test (
250+ 'is modified to include the given encoding if encoding is set and '
251+ 'mime type is xml' , () {
252+ var request = http.Request ('POST' , dummyUrl);
253+ request.headers['Content-Type' ] = 'application/xml' ;
254+ request
255+ ..body = '<?xml...'
256+ ..encoding = latin1;
225257 expect (request.headers['Content-Type' ],
226- equals ('application/json ; charset=utf-8 ' ));
258+ equals ('application/xml ; charset=iso-8859-1 ' ));
227259 });
228260
229- test ('is modified to include the given encoding if encoding is set' , () {
261+ test (
262+ 'is not modified to include the given encoding if encoding is set mime '
263+ 'type is json' , () {
230264 var request = http.Request ('POST' , dummyUrl);
231265 request.headers['Content-Type' ] = 'application/json' ;
232- request.encoding = latin1;
233- expect (request.headers['Content-Type' ],
234- equals ('application/json; charset=iso-8859-1' ));
266+ request
267+ ..body = '{"hello": "world"}'
268+ ..encoding = latin1;
269+ expect (request.headers['Content-Type' ], equals ('application/json' ));
235270 });
236271
237272 test ('has its charset overridden by an explicit encoding' , () {
0 commit comments