-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Experimental HTTP/3 Support (#1599)
This adds experimental HTTP/3 support, using `h3` and `h3-quinn` (though the internals are not to be depended on).
- Loading branch information
Showing
10 changed files
with
742 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
target | ||
Cargo.lock | ||
*.swp | ||
.idea |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#![deny(warnings)] | ||
|
||
// This is using the `tokio` runtime. You'll need the following dependency: | ||
// | ||
// `tokio = { version = "1", features = ["full"] }` | ||
#[cfg(feature = "http3")] | ||
#[cfg(not(target_arch = "wasm32"))] | ||
#[tokio::main] | ||
async fn main() -> Result<(), reqwest::Error> { | ||
use http::Version; | ||
use reqwest::{Client, IntoUrl, Response}; | ||
|
||
async fn get<T: IntoUrl + Clone>(url: T) -> reqwest::Result<Response> { | ||
Client::builder() | ||
.http3_prior_knowledge() | ||
.build()? | ||
.get(url) | ||
.version(Version::HTTP_3) | ||
.send() | ||
.await | ||
} | ||
|
||
// Some simple CLI args requirements... | ||
let url = match std::env::args().nth(1) { | ||
Some(url) => url, | ||
None => { | ||
println!("No CLI URL provided, using default."); | ||
"https://hyper.rs".into() | ||
} | ||
}; | ||
|
||
eprintln!("Fetching {:?}...", url); | ||
|
||
let res = get(url).await?; | ||
|
||
eprintln!("Response: {:?} {}", res.version(), res.status()); | ||
eprintln!("Headers: {:#?}\n", res.headers()); | ||
|
||
let body = res.text().await?; | ||
|
||
println!("{}", body); | ||
|
||
Ok(()) | ||
} | ||
|
||
// The [cfg(not(target_arch = "wasm32"))] above prevent building the tokio::main function | ||
// for wasm32 target, because tokio isn't compatible with wasm32. | ||
// If you aren't building for wasm32, you don't need that line. | ||
// The two lines below avoid the "'main' function not found" error when building for wasm32 target. | ||
#[cfg(any(target_arch = "wasm32", not(feature = "http3")))] | ||
fn main() {} |
Oops, something went wrong.