rustwasm / gloo

A modular toolkit for building fast, reliable Web applications and libraries with Rust and WASM
https://gloo-rs.web.app
Apache License 2.0
1.78k stars 146 forks source link

Can't encode utf-8 strings in headers #491

Open timeteos opened 3 months ago

timeteos commented 3 months ago

Description

Failure to encode utf-8 strings into headers

Steps to Reproduce

let password = "brocolis🥦";

let req = Request::get("https://exemple.com")
    .header("Content-Type", "application/json")
    .header("pswd", password);

Throws the following error in http/headers.rs at line 62 : Cannot convert argument 2 to ByteString because the character at index 8 has value 55358 which is greater than 255.

Probably that there should be some error handling in those functions :

pub fn set(&self, name: &str, value: &str) {
    self.raw.set(name, value).unwrap_throw()
}

Here is some code to easily reproduce the error : reproduct.zip

Expected Behavior

String are just an array of u8, so I would expect the header to be sent with the ASCII representation of the utf-8 string (?)