http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.47k stars 120 forks source link

Crash when malformed uri #134

Open gmg137 opened 4 years ago

gmg137 commented 4 years ago
let res = surf::get("abc").recv_string(data).await;

As above, this will cause the program to crash.

yoshuawuyts commented 4 years ago

Hi, thanks for raising! I've been thinking of how to solve this, and what we probably want is to be able to take TryInto<Url> as the type parameter. For that purpose I've filed:

This would require the usage to:

let res = surf::get("abc")?.recv_string(data).await;

Which would provide graceful error handling rather than directly panicking.


However the solution to your exact issue is to use a fullly-formed url. E.g.

let res = surf::get("http://my-domain.com/abc").recv_string(data).await;
wusyong commented 4 years ago

Do you still want to take TryInto<Url> as parameters? I think this also applies to other methods. I could help a PR if this is what it prefers to be.

goto-bus-stop commented 4 years ago

It looks like TryInto<Url> support is still waiting for a new release of the url crate.