-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade to hyper-v1, use hyper-utils for now
- Loading branch information
1 parent
74044e3
commit d6026c4
Showing
4 changed files
with
80 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
use hyper::{body::HttpBody as _, Client}; | ||
use bytes::Bytes; | ||
use http_body_util::BodyExt; | ||
|
||
use http_body_util::Empty; | ||
use hyper_tls::HttpsConnector; | ||
use hyper_util::{client::legacy::Client, rt::TokioExecutor}; | ||
use tokio::io::{self, AsyncWriteExt as _}; | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let https = HttpsConnector::new(); | ||
let client = Client::builder().build::<_, hyper::Body>(https); | ||
|
||
let client = Client::builder(TokioExecutor::new()).build::<_, Empty<Bytes>>(https); | ||
|
||
let mut res = client.get("https://hyper.rs".parse()?).await?; | ||
|
||
println!("Status: {}", res.status()); | ||
println!("Headers:\n{:#?}", res.headers()); | ||
|
||
while let Some(chunk) = res.body_mut().data().await { | ||
let chunk = chunk?; | ||
io::stdout().write_all(&chunk).await? | ||
while let Some(frame) = res.body_mut().frame().await { | ||
let frame = frame?; | ||
|
||
if let Some(d) = frame.data_ref() { | ||
io::stdout().write_all(d).await?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters