witnet / witnet-rust

Open source Rust implementation of the Witnet decentralized oracle protocol, including full node and wallet backend 👁️🦀
https://docs.witnet.io
GNU General Public License v3.0
180 stars 56 forks source link

Enable retrieval of binary buffers #2274

Closed guidiaz closed 1 year ago

guidiaz commented 2 years ago
tmpolaczyk commented 2 years ago

The conversion from bytes to string is implemented here:

https://github.com/witnet/witnet-rust/blob/63920bd875563741850225dd28ce98849adad299/rad/src/lib.rs#L242-L248

We are using this method from the surf library, which only supports UTF8: https://docs.rs/surf/2.3.2/surf/struct.Response.html#method.body_string

There is a body_bytes method which returns the raw bytes: https://docs.rs/surf/2.3.2/surf/struct.Response.html#method.body_bytes

So we could add a check like:

The only problem is that we cannot access the request headers from RADON to read the content type, so converting the bytes into a string later will only be possible if we know the encoding ahead of time when creating the script. Similarly, when converting string to bytes we need to specify an encoding somehow. But encodings other than UTF8 are not supported yet, so that can be another issue.

Tommytrg commented 1 year ago

Superseeded by #2331