capacitor-community / http

Community plugin for native HTTP
MIT License
209 stars 136 forks source link

feat(web/ios): allow string value in body #196

Closed emily-curry closed 2 years ago

emily-curry commented 2 years ago

This change allows one to use a string value as the body of the request, and have that value be written directly to the request object without any marshalling/unmarshalling to/from JSValue objects.

The use case for this is more of a workaround than a feature. I have observed (though I'm finding it quite difficult to pin down all of the exact conditions), that sometimes with large deeply-nested objects, that the conversion from POJO -> capacitor bridge -> JSValue -> JSObject is not always consistent between platforms, and sometimes omits data. For example, on Android, if I have a POJO with a key that is the literal value null, when a JSObject is constructed from that object, that key+value pair is omitted. In my opinion, it is very important that for this plugin in particular we are able to guarantee that the requests are sent exactly as written. Sending strings over the bridge allows us to have that guarantee, at least for non-binary utf8 content. If https://github.com/ionic-team/capacitor/issues/984 is implemented, blobs and maybe typedarrays could be future enhancements that give that guarantee for all data.

No changes were made to the Android implementation because this is already the current behavior, it just writes strings as-is.

This is based on #149, because it touches some of the same code and would cause conflicts.