nickel-org / nickel.rs

An expressjs inspired web framework for Rust

Home Page:http://nickel-org.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How tu set utf-8 ?

imclint21 opened this issue · comments

Hi,

I currently create a KV store with an HTTP API (lucid) and I return a Vec<u8> with the res.send(value) method, but when I check the URL, some emoji does not works, and the encoding is windows-1252.

How can I set UTF-8 ?

Thanks!

I specify that I set by default: res.set(MediaType::Txt)

Yes with Json output, I don't have this problem 😂

So the question is, how to set a generic mimetype, that display text or json when it's the case and display image when its the case too, and does not download a file without extension ? 😁

res.send takes something that implements the Responder trait, which has several default implementations. Vec<u8> sets its media type to MediaType::Bin, while String uses MediaType::Html. I think the easiest approach would be to convert the Vec<u8> to a String with String::from_utf8 or String::from_utf8_lossy

Do you sleep sometimes? ^^

But thank you, I will try!

Also, how to set a custom mime type like text/csv or other directly from string without MediaType type ?

It's only 7pm here in Seattle :-)

If you set the MediaType explicitly, the automatic setting should be skipped. res.set(MediaType::Csv) ought to work. Let me know if it doesn't. There may be a bug.

Yes but justly, how to do it, how to set the mime-type from a string?

From within the String, you can't. You need something like this:

data = "some, data\nmore,data\n".to_string();
res.set(MedisType:Csv);
res.send(data)

Thank you