summaryrefslogtreecommitdiff
path: root/runtime/ops/http.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-01-22 22:35:39 +0100
committerGitHub <noreply@github.com>2024-01-22 21:35:39 +0000
commit71551c80a1c7ea2cc75cf82c5871212559709789 (patch)
tree6d5e458e54ea6598d78d6b4d7177006a9048deb6 /runtime/ops/http.rs
parent69d5f136badfd7cfa9b979ff2fee7caf397098ca (diff)
feat(unstable): remove Deno.upgradeHttp API (#21856)
Closes https://github.com/denoland/deno/issues/21828. This API is a huge footgun. And given that "Deno.serveHttp" is a deprecated API that is discouraged to use (use "Deno.serve()" instead); it makes no sense to keep this API around. This is a step towards fully migrating to Hyper 1.
Diffstat (limited to 'runtime/ops/http.rs')
-rw-r--r--runtime/ops/http.rs96
1 files changed, 1 insertions, 95 deletions
diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs
index 07ad7bcb6..ca51b001d 100644
--- a/runtime/ops/http.rs
+++ b/runtime/ops/http.rs
@@ -1,38 +1,22 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-use std::cell::RefCell;
use std::rc::Rc;
use deno_core::error::bad_resource;
use deno_core::error::bad_resource_id;
-use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::op2;
use deno_core::OpState;
-use deno_core::RcRef;
use deno_core::ResourceId;
use deno_core::ToJsBuffer;
use deno_http::http_create_conn_resource;
-use deno_http::HttpRequestReader;
-use deno_http::HttpStreamResource;
use deno_net::io::TcpStreamResource;
-use deno_net::ops_tls::TlsStream;
use deno_net::ops_tls::TlsStreamResource;
-use hyper_v014::upgrade::Parts;
use serde::Serialize;
-use tokio::net::TcpStream;
-
-#[cfg(unix)]
-use deno_net::io::UnixStreamResource;
-#[cfg(unix)]
-use tokio::net::UnixStream;
pub const UNSTABLE_FEATURE_NAME: &str = "http";
-deno_core::extension!(
- deno_http_runtime,
- ops = [op_http_start, op_http_upgrade],
-);
+deno_core::extension!(deno_http_runtime, ops = [op_http_start],);
#[op2(fast)]
#[smi]
@@ -98,81 +82,3 @@ pub struct HttpUpgradeResult {
conn_type: &'static str,
read_buf: ToJsBuffer,
}
-
-#[op2(async)]
-#[serde]
-async fn op_http_upgrade(
- state: Rc<RefCell<OpState>>,
- #[smi] rid: ResourceId,
-) -> Result<HttpUpgradeResult, AnyError> {
- let stream = state
- .borrow_mut()
- .resource_table
- .get::<HttpStreamResource>(rid)?;
- let mut rd = RcRef::map(&stream, |r| &r.rd).borrow_mut().await;
-
- let request = match &mut *rd {
- HttpRequestReader::Headers(request) => request,
- _ => {
- return Err(custom_error(
- "Http",
- "cannot upgrade because request body was used",
- ))
- }
- };
-
- let transport = hyper_v014::upgrade::on(request).await?;
- let transport = match transport.downcast::<TcpStream>() {
- Ok(Parts {
- io: tcp_stream,
- read_buf,
- ..
- }) => {
- return Ok(HttpUpgradeResult {
- conn_type: "tcp",
- conn_rid: state
- .borrow_mut()
- .resource_table
- .add(TcpStreamResource::new(tcp_stream.into_split())),
- read_buf: read_buf.to_vec().into(),
- });
- }
- Err(transport) => transport,
- };
- #[cfg(unix)]
- let transport = match transport.downcast::<UnixStream>() {
- Ok(Parts {
- io: unix_stream,
- read_buf,
- ..
- }) => {
- return Ok(HttpUpgradeResult {
- conn_type: "unix",
- conn_rid: state
- .borrow_mut()
- .resource_table
- .add(UnixStreamResource::new(unix_stream.into_split())),
- read_buf: read_buf.to_vec().into(),
- });
- }
- Err(transport) => transport,
- };
- match transport.downcast::<TlsStream>() {
- Ok(Parts {
- io: tls_stream,
- read_buf,
- ..
- }) => Ok(HttpUpgradeResult {
- conn_type: "tls",
- conn_rid: state
- .borrow_mut()
- .resource_table
- .add(TlsStreamResource::new(tls_stream.into_split())),
- read_buf: read_buf.to_vec().into(),
- }),
- Err(_) => Err(custom_error(
- "Http",
- "encountered unsupported transport while upgrading",
- )),
- }
-}