Skip to content
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

Allow xhr to return raw response without UTF-8 decoding in flutter_js #137

Open
zhouxiaofu opened this issue Sep 20, 2023 · 1 comment
Open

Comments

@zhouxiaofu
Copy link

zhouxiaofu commented Sep 20, 2023

Description:

Hello maintainers,

I'm currently using flutter_js for my project and I've encountered a scenario where the default UTF-8 decoding of the xhr response isn't suitable for my needs. Specifically, some of the content I'm fetching might be in GBK encoding, and I'm handling the conversion using iconv on the JS side.

Current behavior:

String responseText = utf8.decode(response.bodyBytes);

This automatic decoding poses a challenge when dealing with non-UTF-8 encoded content.

Error:

E/flutter (21984): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Missing extension byte (at offset 102)
E/flutter (21984): #0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1747:7)
E/flutter (21984): #1      Utf8Decoder.convert (dart:convert/utf.dart:351:42)
E/flutter (21984): #2      Utf8Codec.decode (dart:convert/utf.dart:63:20)
E/flutter (21984): #3      JavascriptRuntimeXhrExtension.enableXhr.<anonymous closure>.<anonymous closure> (package:flutter_js/extensions/xhr.dart:326:36)
E/flutter (21984): <asynchronous suspension>

Feature Request:

It would be great if there was an option or configuration to get the raw response from xhr, without any decoding, allowing the JS to handle the decoding (if necessary) based on the content type or other factors.

Use Case:

In my scenario, I'm dealing with content that could be either UTF-8 or GBK encoded. Having the raw bytes allows me to use libraries like iconv in the JS environment to handle decoding correctly based on the actual encoding of the content.

Thank you for considering this request. I believe it would make flutter_js more flexible in handling various content types and encodings.

@abner
Copy link
Owner

abner commented Sep 24, 2023

I will take a look on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants