mirror of
https://github.com/denoland/deno.git
synced 2024-11-30 16:40:57 -05:00
refactor: rewrite remaining test server to Hyper 1.1 (#21708)
Ref https://github.com/denoland/deno/issues/21578
This commit is contained in:
parent
936d265f8a
commit
7a90ea3053
4 changed files with 442 additions and 300 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -5969,15 +5969,15 @@ dependencies = [
|
||||||
"base64 0.21.5",
|
"base64 0.21.5",
|
||||||
"bytes",
|
"bytes",
|
||||||
"console_static_text",
|
"console_static_text",
|
||||||
|
"deno_unsync 0.3.0",
|
||||||
"denokv_proto",
|
"denokv_proto",
|
||||||
"fastwebsockets",
|
"fastwebsockets",
|
||||||
"flate2",
|
"flate2",
|
||||||
"futures",
|
"futures",
|
||||||
"glob",
|
"glob",
|
||||||
"h2 0.3.22",
|
|
||||||
"h2 0.4.0",
|
"h2 0.4.0",
|
||||||
"http 1.0.0",
|
"http 1.0.0",
|
||||||
"hyper 0.14.27",
|
"http-body-util",
|
||||||
"hyper 1.1.0",
|
"hyper 1.1.0",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"lazy-regex",
|
"lazy-regex",
|
||||||
|
|
|
@ -19,15 +19,15 @@ async-stream = "0.3.3"
|
||||||
base64.workspace = true
|
base64.workspace = true
|
||||||
bytes.workspace = true
|
bytes.workspace = true
|
||||||
console_static_text.workspace = true
|
console_static_text.workspace = true
|
||||||
|
deno_unsync = "0.3.0"
|
||||||
denokv_proto.workspace = true
|
denokv_proto.workspace = true
|
||||||
fastwebsockets.workspace = true
|
fastwebsockets.workspace = true
|
||||||
flate2 = { workspace = true, features = ["default"] }
|
flate2 = { workspace = true, features = ["default"] }
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
glob.workspace = true
|
glob.workspace = true
|
||||||
h2.workspace = true
|
|
||||||
h2_04 = { package = "h2", version = "0.4" }
|
h2_04 = { package = "h2", version = "0.4" }
|
||||||
|
http-body-util = "0.1"
|
||||||
http_1 = { package = "http", version = "1.0" }
|
http_1 = { package = "http", version = "1.0" }
|
||||||
hyper = { workspace = true, features = ["server", "http1", "http2", "runtime"] }
|
|
||||||
hyper-util.workspace = true
|
hyper-util.workspace = true
|
||||||
hyper1.workspace = true
|
hyper1.workspace = true
|
||||||
lazy-regex.workspace = true
|
lazy-regex.workspace = true
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,37 +1,38 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use hyper::server::Server;
|
use super::run_hyper1_server;
|
||||||
use hyper::service::make_service_fn;
|
use bytes::Bytes;
|
||||||
use hyper::service::service_fn;
|
use http_body_util::combinators::UnsyncBoxBody;
|
||||||
use hyper::Body;
|
use http_body_util::Empty;
|
||||||
use hyper::Request;
|
use http_body_util::Full;
|
||||||
use hyper::Response;
|
use hyper1::body::Incoming;
|
||||||
use hyper::StatusCode;
|
use hyper1::Request;
|
||||||
|
use hyper1::Response;
|
||||||
|
use hyper1::StatusCode;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
pub async fn registry_server(port: u16) {
|
pub async fn registry_server(port: u16) {
|
||||||
let registry_server_addr = SocketAddr::from(([127, 0, 0, 1], port));
|
let registry_server_addr = SocketAddr::from(([127, 0, 0, 1], port));
|
||||||
let registry_server_svc = make_service_fn(|_| async {
|
|
||||||
Ok::<_, Infallible>(service_fn(registry_server_handler))
|
run_hyper1_server(
|
||||||
});
|
registry_server_addr,
|
||||||
let registry_server =
|
registry_server_handler,
|
||||||
Server::bind(®istry_server_addr).serve(registry_server_svc);
|
"Registry server error",
|
||||||
if let Err(e) = registry_server.await {
|
)
|
||||||
eprintln!("Registry server error: {:?}", e);
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn registry_server_handler(
|
async fn registry_server_handler(
|
||||||
req: Request<Body>,
|
req: Request<Incoming>,
|
||||||
) -> Result<Response<Body>, hyper::http::Error> {
|
) -> Result<Response<UnsyncBoxBody<Bytes, Infallible>>, anyhow::Error> {
|
||||||
let path = req.uri().path();
|
let path = req.uri().path();
|
||||||
|
|
||||||
// TODO(bartlomieju): add a proper router here
|
// TODO(bartlomieju): add a proper router here
|
||||||
if path.starts_with("/api/scope/") {
|
if path.starts_with("/api/scope/") {
|
||||||
let body = serde_json::to_string_pretty(&json!({})).unwrap();
|
let body = serde_json::to_string_pretty(&json!({})).unwrap();
|
||||||
let res = Response::new(Body::from(body));
|
let res = Response::new(UnsyncBoxBody::new(Full::from(body)));
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
} else if path.starts_with("/api/scopes/") {
|
} else if path.starts_with("/api/scopes/") {
|
||||||
let body = serde_json::to_string_pretty(&json!({
|
let body = serde_json::to_string_pretty(&json!({
|
||||||
|
@ -40,7 +41,7 @@ async fn registry_server_handler(
|
||||||
"error": null
|
"error": null
|
||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = Response::new(Body::from(body));
|
let res = Response::new(UnsyncBoxBody::new(Full::from(body)));
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
} else if path.starts_with("/api/publish_status/") {
|
} else if path.starts_with("/api/publish_status/") {
|
||||||
let body = serde_json::to_string_pretty(&json!({
|
let body = serde_json::to_string_pretty(&json!({
|
||||||
|
@ -49,11 +50,13 @@ async fn registry_server_handler(
|
||||||
"error": null
|
"error": null
|
||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = Response::new(Body::from(body));
|
let res = Response::new(UnsyncBoxBody::new(Full::from(body)));
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::builder()
|
let empty_body = UnsyncBoxBody::new(Empty::new());
|
||||||
|
let res = Response::builder()
|
||||||
.status(StatusCode::NOT_FOUND)
|
.status(StatusCode::NOT_FOUND)
|
||||||
.body(Body::empty())
|
.body(empty_body)?;
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue