summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-12-27 17:59:57 +0100
committerGitHub <noreply@github.com>2023-12-27 11:59:57 -0500
commitc2414db1f68d27db8ca6f192f0ff877f1394164c (patch)
tree528da9796f400557204bfdb8e4d44d64173036ce /runtime
parent33acd437f52b418a8413a302dd8902abad2eabec (diff)
refactor: simplify hyper, http, h2 deps (#21715)
Main change is that: - "hyper" has been renamed to "hyper_v014" to signal that it's legacy - "hyper1" has been renamed to "hyper" and should be the default
Diffstat (limited to 'runtime')
-rw-r--r--runtime/Cargo.toml5
-rw-r--r--runtime/errors.rs9
-rw-r--r--runtime/inspector_server.rs58
-rw-r--r--runtime/ops/http.rs4
4 files changed, 39 insertions, 37 deletions
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml
index 7ac7a803b..9bfe977a2 100644
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -102,10 +102,9 @@ filetime = "0.2.16"
fs3.workspace = true
http.workspace = true
http-body-util.workspace = true
-http_1 = { package = "http", version = "1.0" }
-hyper = { workspace = true, features = ["server", "stream", "http1", "http2", "runtime"] }
+hyper.workspace = true
hyper-util.workspace = true
-hyper1.workspace = true
+hyper_v014 = { workspace = true, features = ["server", "stream", "http1", "http2", "runtime"] }
libc.workspace = true
log.workspace = true
netif = "0.1.6"
diff --git a/runtime/errors.rs b/runtime/errors.rs
index c05e5bd62..96a827dd3 100644
--- a/runtime/errors.rs
+++ b/runtime/errors.rs
@@ -142,7 +142,7 @@ fn get_url_parse_error_class(_error: &url::ParseError) -> &'static str {
"URIError"
}
-fn get_hyper_error_class(_error: &hyper::Error) -> &'static str {
+fn get_hyper_error_class(_error: &hyper_v014::Error) -> &'static str {
"Http"
}
@@ -175,9 +175,12 @@ pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> {
e.downcast_ref::<dlopen2::Error>()
.map(get_dlopen_error_class)
})
- .or_else(|| e.downcast_ref::<hyper::Error>().map(get_hyper_error_class))
.or_else(|| {
- e.downcast_ref::<Arc<hyper::Error>>()
+ e.downcast_ref::<hyper_v014::Error>()
+ .map(get_hyper_error_class)
+ })
+ .or_else(|| {
+ e.downcast_ref::<Arc<hyper_v014::Error>>()
.map(|e| get_hyper_error_class(e))
})
.or_else(|| {
diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs
index ad9cc9d7f..1c85b001d 100644
--- a/runtime/inspector_server.rs
+++ b/runtime/inspector_server.rs
@@ -104,11 +104,11 @@ impl Drop for InspectorServer {
}
fn handle_ws_request(
- req: http_1::Request<hyper1::body::Incoming>,
+ req: http::Request<hyper::body::Incoming>,
inspector_map_rc: Rc<RefCell<HashMap<Uuid, InspectorInfo>>>,
-) -> http_1::Result<http_1::Response<Box<http_body_util::Full<Bytes>>>> {
+) -> http::Result<http::Response<Box<http_body_util::Full<Bytes>>>> {
let (parts, body) = req.into_parts();
- let req = http_1::Request::from_parts(parts, ());
+ let req = http::Request::from_parts(parts, ());
let maybe_uuid = req
.uri()
@@ -117,8 +117,8 @@ fn handle_ws_request(
.and_then(|s| Uuid::parse_str(s).ok());
if maybe_uuid.is_none() {
- return http_1::Response::builder()
- .status(http_1::StatusCode::BAD_REQUEST)
+ return http::Response::builder()
+ .status(http::StatusCode::BAD_REQUEST)
.body(Box::new(Bytes::from("Malformed inspector UUID").into()));
}
@@ -128,8 +128,8 @@ fn handle_ws_request(
let maybe_inspector_info = inspector_map.get(&maybe_uuid.unwrap());
if maybe_inspector_info.is_none() {
- return http_1::Response::builder()
- .status(http_1::StatusCode::NOT_FOUND)
+ return http::Response::builder()
+ .status(http::StatusCode::NOT_FOUND)
.body(Box::new(Bytes::from("Invalid inspector UUID").into()));
}
@@ -137,20 +137,20 @@ fn handle_ws_request(
info.new_session_tx.clone()
};
let (parts, _) = req.into_parts();
- let mut req = http_1::Request::from_parts(parts, body);
+ let mut req = http::Request::from_parts(parts, body);
let (resp, fut) = match fastwebsockets::upgrade::upgrade(&mut req) {
Ok((resp, fut)) => {
let (parts, _body) = resp.into_parts();
- let resp = http_1::Response::from_parts(
+ let resp = http::Response::from_parts(
parts,
Box::new(http_body_util::Full::new(Bytes::new())),
);
(resp, fut)
}
_ => {
- return http_1::Response::builder()
- .status(http_1::StatusCode::BAD_REQUEST)
+ return http::Response::builder()
+ .status(http::StatusCode::BAD_REQUEST)
.body(Box::new(
Bytes::from("Not a valid Websocket Request").into(),
));
@@ -192,7 +192,7 @@ fn handle_ws_request(
fn handle_json_request(
inspector_map: Rc<RefCell<HashMap<Uuid, InspectorInfo>>>,
host: Option<String>,
-) -> http_1::Result<http_1::Response<Box<http_body_util::Full<Bytes>>>> {
+) -> http::Result<http::Response<Box<http_body_util::Full<Bytes>>>> {
let data = inspector_map
.borrow()
.values()
@@ -200,22 +200,22 @@ fn handle_json_request(
.collect::<Vec<_>>();
let body: http_body_util::Full<Bytes> =
Bytes::from(serde_json::to_string(&data).unwrap()).into();
- http_1::Response::builder()
- .status(http_1::StatusCode::OK)
- .header(http_1::header::CONTENT_TYPE, "application/json")
+ http::Response::builder()
+ .status(http::StatusCode::OK)
+ .header(http::header::CONTENT_TYPE, "application/json")
.body(Box::new(body))
}
fn handle_json_version_request(
version_response: Value,
-) -> http_1::Result<http_1::Response<Box<http_body_util::Full<Bytes>>>> {
+) -> http::Result<http::Response<Box<http_body_util::Full<Bytes>>>> {
let body = Box::new(http_body_util::Full::from(
serde_json::to_string(&version_response).unwrap(),
));
- http_1::Response::builder()
- .status(http_1::StatusCode::OK)
- .header(http_1::header::CONTENT_TYPE, "application/json")
+ http::Response::builder()
+ .status(http::StatusCode::OK)
+ .header(http::header::CONTENT_TYPE, "application/json")
.body(body)
}
@@ -296,8 +296,8 @@ async fn server(
let json_version_response = json_version_response.clone();
let mut shutdown_server_rx = shutdown_server_rx.resubscribe();
- let service = hyper1::service::service_fn(
- move |req: http_1::Request<hyper1::body::Incoming>| {
+ let service = hyper::service::service_fn(
+ move |req: http::Request<hyper::body::Incoming>| {
future::ready({
// If the host header can make a valid URL, use it
let host = req
@@ -311,20 +311,20 @@ async fn server(
_ => None,
});
match (req.method(), req.uri().path()) {
- (&http_1::Method::GET, path) if path.starts_with("/ws/") => {
+ (&http::Method::GET, path) if path.starts_with("/ws/") => {
handle_ws_request(req, Rc::clone(&inspector_map))
}
- (&http_1::Method::GET, "/json/version") => {
+ (&http::Method::GET, "/json/version") => {
handle_json_version_request(json_version_response.clone())
}
- (&http_1::Method::GET, "/json") => {
+ (&http::Method::GET, "/json") => {
handle_json_request(Rc::clone(&inspector_map), host)
}
- (&http_1::Method::GET, "/json/list") => {
+ (&http::Method::GET, "/json/list") => {
handle_json_request(Rc::clone(&inspector_map), host)
}
- _ => http_1::Response::builder()
- .status(http_1::StatusCode::NOT_FOUND)
+ _ => http::Response::builder()
+ .status(http::StatusCode::NOT_FOUND)
.body(Box::new(http_body_util::Full::new(Bytes::from(
"Not Found",
)))),
@@ -334,7 +334,7 @@ async fn server(
);
deno_core::unsync::spawn(async move {
- let server = hyper1::server::conn::http1::Builder::new();
+ let server = hyper::server::conn::http1::Builder::new();
let mut conn =
pin!(server.serve_connection(io, service).with_upgrades());
@@ -376,7 +376,7 @@ async fn server(
/// 'futures' crate, therefore they can't participate in Tokio's cooperative
/// task yielding.
async fn pump_websocket_messages(
- mut websocket: WebSocket<TokioIo<hyper1::upgrade::Upgraded>>,
+ mut websocket: WebSocket<TokioIo<hyper::upgrade::Upgraded>>,
inbound_tx: UnboundedSender<String>,
mut outbound_rx: UnboundedReceiver<InspectorMsg>,
) {
diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs
index fc66c9fab..65a990dd9 100644
--- a/runtime/ops/http.rs
+++ b/runtime/ops/http.rs
@@ -18,7 +18,7 @@ use deno_http::HttpStreamResource;
use deno_net::io::TcpStreamResource;
use deno_net::ops_tls::TlsStream;
use deno_net::ops_tls::TlsStreamResource;
-use hyper::upgrade::Parts;
+use hyper_v014::upgrade::Parts;
use serde::Serialize;
use tokio::net::TcpStream;
@@ -121,7 +121,7 @@ async fn op_http_upgrade(
}
};
- let transport = hyper::upgrade::on(request).await?;
+ let transport = hyper_v014::upgrade::on(request).await?;
let transport = match transport.downcast::<TcpStream>() {
Ok(Parts {
io: tcp_stream,