Update to hyper 1.0-rc.3 and http-body-util 0.1.0-rc.2

This commit is contained in:
David Pedersen
2023-03-23 23:23:39 +01:00
parent 44bb38dfa2
commit c73b6a9969
41 changed files with 790 additions and 816 deletions
+1
View File
@@ -6,6 +6,7 @@ publish = false
[dependencies]
axum = { path = "../../axum" }
http-body-util = "0.1.0-rc.2"
hyper = { version = "1.0.0-rc.3", features = ["full"] }
mime = "0.3"
serde_json = "1.0"
+24 -21
View File
@@ -59,11 +59,12 @@ mod tests {
extract::connect_info::MockConnectInfo,
http::{self, Request, StatusCode},
};
use http_body_util::BodyExt;
use serde_json::{json, Value};
use std::net::SocketAddr;
use tokio::net::TcpListener;
use tower::Service; // for `call`
use tower::ServiceExt; // for `oneshot` and `ready`
use tower::ServiceExt; // for `oneshot` and `ready` // for `collect`
#[tokio::test]
async fn hello_world() {
@@ -78,7 +79,7 @@ mod tests {
assert_eq!(response.status(), StatusCode::OK);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = response.into_body().collect().await.unwrap().to_bytes();
assert_eq!(&body[..], b"Hello, World!");
}
@@ -102,7 +103,7 @@ mod tests {
assert_eq!(response.status(), StatusCode::OK);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = response.into_body().collect().await.unwrap().to_bytes();
let body: Value = serde_json::from_slice(&body).unwrap();
assert_eq!(body, json!({ "data": [1, 2, 3, 4] }));
}
@@ -122,34 +123,36 @@ mod tests {
.unwrap();
assert_eq!(response.status(), StatusCode::NOT_FOUND);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = response.into_body().collect().await.unwrap().to_bytes();
assert!(body.is_empty());
}
// You can also spawn a server and talk to it like any other HTTP server:
#[tokio::test]
async fn the_real_deal() {
let listener = TcpListener::bind("0.0.0.0:0").await.unwrap();
let addr = listener.local_addr().unwrap();
todo!();
tokio::spawn(async move {
axum::serve(listener, app()).await.unwrap();
});
// let listener = TcpListener::bind("0.0.0.0:0").await.unwrap();
// let addr = listener.local_addr().unwrap();
let client = hyper::Client::new();
// tokio::spawn(async move {
// axum::serve(listener, app()).await.unwrap();
// });
let response = client
.request(
Request::builder()
.uri(format!("http://{}", addr))
.body(hyper::Body::empty())
.unwrap(),
)
.await
.unwrap();
// let client = hyper::Client::new();
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
assert_eq!(&body[..], b"Hello, World!");
// let response = client
// .request(
// Request::builder()
// .uri(format!("http://{}", addr))
// .body(axum::Body::empty())
// .unwrap(),
// )
// .await
// .unwrap();
// let body = response.into_body().collect().await.unwrap().to_bytes();
// assert_eq!(&body[..], b"Hello, World!");
}
// You can use `ready()` and `call()` to avoid using `clone()`