[dart2] [client] Check request .bodyBytes, not .body
fix #17546
This PR is part of the effort to split PR #17548
Changes request parsing from checking .body.isNotEmpty to .bodyBytes.isNotEmpty, because .body implicitly converts to a utf-8 string, and will crash when trying to deserde data that isn't valid utf-8.
@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)
How a byte array isn't a valid utf8 string(?)?
No matching octet sequence or just unknown/invalid unicode. Makes sense to me, but can anyone test this? :)
How a byte array isn't a valid utf8 string(?)?
For example, an endpoint that returns the bytes of a jpeg. Or an endpoint that serves utf16 strings.
In my case it was image data that caused exceptions, but endpoints can serve any encoding of byte, and every encoding is not valid utf8.
for testing, we can consider adding echo api client for dart. We already have an endpoint to return a gif, we can create another endpoint to return a utf6 string.
@0xNF ping me if you need help adding the Dart echo api client to perform integration tests.