-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace hyper with reqwest #7
Conversation
|
|
Down to 9 errors, the first about a boxed logger looks familiar, when updating |
Old syntax: let res = try!(client.post(LOGIN_URL.parse::<hyper::Uri>().unwrap())
.body(&req)
.header(hyper::header::CONTENT_TYPE, "application/json")
.send()); New syntax from https://docs.rs/hyper/0.12.12/hyper/struct.Request.html, instead of client.post() pass this to client.request(): let request = Request::builder()
.method("GET")
.uri("https://www.rust-lang.org/")
.header("X-Custom-Foo", "Bar")
.body(())
.unwrap(); |
Converted but client.request(request) returns a ResponseFuture, may need to map() it or as in https://github.com/hyperium/hyper/blob/09156a70a63ce1740bc0d3ecff9db5861bffb389/examples/client_json.rs#L46 client
// Fetch the url...
.get(url)
// And then, if we get a response back...
.and_then(|res| {
// asynchronously concatenate chunks of the body
res.into_body().concat2()
}) This also explains the missing method errors in ResponseFuture: error[E0599]: no method named need to update to resolve the ResponseFuture |
How to parse JSON from a response? Example uses futures: https://github.com/hyperium/hyper/blob/master/examples/client_json.rs#L39 |
It is convoluted, but this seems to compile: let ret: serde_json::Value = try!(serde_json::from_slice(&res.into_body().concat2().wait().unwrap().into_bytes())); |
…slice, instead of from_reader which didn't compile
let mut progress = ProgressRead {
read: res,
progress: &progress_info,
task_name: "Downloading Asset Index".into(),
task_file: location.to_string_lossy().into_owned(),
};
io::copy(&mut progress, &mut file).unwrap(); Need to get the std::io::Read trait from hyper::Responsehyper::Body:
|
Down to 1 mysterious compile error:
log 0.4.5 updated in 43f6565#diff-639fbc4ef05b315af92b4d836c31b023, this change: - log::set_logger(|max_log_level| {
- max_log_level.set(log::LogLevelFilter::Trace);
- Box::new(proxy)
- }).unwrap();
+ log::set_boxed_logger(Box::new(proxy)).unwrap();
+ log::set_max_level(log::LevelFilter::Trace); but it worked before the pub fn init() -> Result<(), SetLoggerError> {
log::set_boxed_logger(Box::new(SimpleLogger))
.map(|()| log::set_max_level(LevelFilter::Info))
} not |
https://hyper.rs/guides/client/configuration/
extern crate hyper;
extern crate hyper_tls;
use hyper::Client;
use hyper_tls::HttpsConnector;
let https = HttpsConnector::new(4).expect("TLS initialization failed");
let client = Client::builder()
.build::<_, hyper::Body>(https); |
hyper-tls uses native-ssl which seems to use OpenSSL, something I want to avoid (https://github.com/iceiix/steven/issues/2). rustls is a Rust implementation of TLS. For why hyper-tls was split out see hyperium/hyper#985, long story short to avoid explicit OpenSSL dependency. Looks like hyper-rustls provides the integration: https://github.com/ctz/hyper-rustls |
Converting to reqwest is sounding more and more attractive. Hyper getting started https://users.rust-lang.org/t/hyper-client-getting-started/19260 points to reqwest even... |
https://docs.rs/reqwest/0.9.4/reqwest/
this is very nice, solves this problem #7 (comment) which I tried to workaround with the ugly: let ret: serde_json::Value = try!(serde_json::from_slice(&res.into_body().concat2().wait().unwrap().into_bytes())); with reqwest, from_reader() can be used directly on the response since it implements std::io::Read! let ret: serde_json::Value = try!(serde_json::from_reader(res)); |
This is basically done but the mysterious log::set_boxed_error error still occurs, first seen with hyper 0.12.11 but it persists with reqwest 0.9.4 (not seen with the original hyper 0.8.0). rust-lang/log#303 |
https://github.com/iceiix/steven/issues/4#issuecomment-425759778