Jonny Borges
Committed by GitHub

Merge pull request #1424 from heftekharm/response-fix-encoding

changed response default encoding from latin1 to utf8
@@ -60,14 +60,13 @@ class Response<T> { @@ -60,14 +60,13 @@ class Response<T> {
60 final T? body; 60 final T? body;
61 } 61 }
62 62
63 -Future<String> bodyBytesToString(  
64 - Stream<List<int>> bodyBytes, Map<String, String> headers) { 63 +Future<String> bodyBytesToString(Stream<List<int>> bodyBytes, Map<String, String> headers) {
65 return bodyBytes.bytesToString(_encodingForHeaders(headers)); 64 return bodyBytes.bytesToString(_encodingForHeaders(headers));
66 } 65 }
67 66
68 /// Returns the encoding to use for a response with the given headers. 67 /// Returns the encoding to use for a response with the given headers.
69 /// 68 ///
70 -/// Defaults to [latin1] if the headers don't specify a charset or if that 69 +/// Defaults to [utf8] if the headers don't specify a charset or if that
71 /// charset is unknown. 70 /// charset is unknown.
72 Encoding _encodingForHeaders(Map<String, String> headers) => 71 Encoding _encodingForHeaders(Map<String, String> headers) =>
73 _encodingForCharset(_contentTypeForHeaders(headers).parameters!['charset']); 72 _encodingForCharset(_contentTypeForHeaders(headers).parameters!['charset']);
@@ -76,7 +75,7 @@ Encoding _encodingForHeaders(Map<String, String> headers) => @@ -76,7 +75,7 @@ Encoding _encodingForHeaders(Map<String, String> headers) =>
76 /// 75 ///
77 /// Returns [fallback] if [charset] is null or if no [Encoding] was found that 76 /// Returns [fallback] if [charset] is null or if no [Encoding] was found that
78 /// corresponds to [charset]. 77 /// corresponds to [charset].
79 -Encoding _encodingForCharset(String? charset, [Encoding fallback = latin1]) { 78 +Encoding _encodingForCharset(String? charset, [Encoding fallback = utf8]) {
80 if (charset == null) return fallback; 79 if (charset == null) return fallback;
81 return Encoding.getByName(charset) ?? fallback; 80 return Encoding.getByName(charset) ?? fallback;
82 } 81 }
@@ -102,9 +101,7 @@ class HeaderValue { @@ -102,9 +101,7 @@ class HeaderValue {
102 } 101 }
103 102
104 static HeaderValue parse(String value, 103 static HeaderValue parse(String value,
105 - {String parameterSeparator = ';',  
106 - String? valueSeparator,  
107 - bool preserveBackslash = false}) { 104 + {String parameterSeparator = ';', String? valueSeparator, bool preserveBackslash = false}) {
108 var result = HeaderValue(); 105 var result = HeaderValue();
109 result._parse(value, parameterSeparator, valueSeparator, preserveBackslash); 106 result._parse(value, parameterSeparator, valueSeparator, preserveBackslash);
110 return result; 107 return result;
@@ -134,8 +131,7 @@ class HeaderValue { @@ -134,8 +131,7 @@ class HeaderValue {
134 return stringBuffer.toString(); 131 return stringBuffer.toString();
135 } 132 }
136 133
137 - void _parse(String value, String parameterSeparator, String? valueSeparator,  
138 - bool preserveBackslash) { 134 + void _parse(String value, String parameterSeparator, String? valueSeparator, bool preserveBackslash) {
139 var index = 0; 135 var index = 0;
140 136
141 bool done() => index == value.length; 137 bool done() => index == value.length;