Open rostopira opened 5 years ago
@rostopira our team recently encountered an almost identical problem, except we were trying to do GZip. We even went down the same path. I also tried fixing _defaultEncoding
so that when encoding
was set that encoding would be acknowledged, but this threw handshake errors.
However, the solution was not recycling the original request (the mutable members are misleading) but instead recreating the request and then adding the encoded value to bodyFields
:
if (request is! http.Request) return innerClient.send(request);
final httpRequest = request as http.Request;
if (httpRequest.body == null || httpRequest.body.isEmpty) return innerClient.send(request);
var newRequest = http.Request(httpRequest.method, httpRequest.url);
newRequest.headers.addAll(httpRequest.headers);
newRequest.bodyBytes = _encoder.encode(httpRequest.bodyBytes);
newRequest.headers['Content-Encoding'] = 'gzip';
return innerClient.send(newRequest);
I discovered this after reviewing the source for _sendUnstreamed. The full pull request is here if you want to look at the complete code.
cc @Pholey @DenchikBY @anisalibegic from your reactions
I need to send post request with
cp1251
encoding I've extendedEncoding
class with following code_MAP
is just chars map for this encoding But using it throws an errorI've tried to replace encoding name with
"ascii"
, but it throws as wellHow can I use non-default encoding?