summaryrefslogtreecommitdiff
path: root/ext/http
diff options
context:
space:
mode:
Diffstat (limited to 'ext/http')
-rw-r--r--ext/http/00_serve.js15
-rw-r--r--ext/http/http_next.rs19
-rw-r--r--ext/http/lib.rs2
3 files changed, 12 insertions, 24 deletions
diff --git a/ext/http/00_serve.js b/ext/http/00_serve.js
index 1746b1d47..69ad88566 100644
--- a/ext/http/00_serve.js
+++ b/ext/http/00_serve.js
@@ -49,8 +49,6 @@ const {
} = primordials;
const {
- op_http_wait,
- op_http_upgrade_next,
op_http_get_request_headers,
op_http_get_request_method_and_url,
op_http_read_request_body,
@@ -63,10 +61,9 @@ const {
op_http_set_response_header,
op_http_set_response_headers,
op_http_upgrade_raw,
- op_ws_server_create,
+ op_http_upgrade_websocket_next,
+ op_http_wait,
} = core.generateAsyncOpHandler(
- "op_http_wait",
- "op_http_upgrade_next",
"op_http_get_request_headers",
"op_http_get_request_method_and_url",
"op_http_read_request_body",
@@ -79,7 +76,8 @@ const {
"op_http_set_response_header",
"op_http_set_response_headers",
"op_http_upgrade_raw",
- "op_ws_server_create",
+ "op_http_upgrade_websocket_next",
+ "op_http_wait",
);
const _upgraded = Symbol("_upgraded");
@@ -208,12 +206,11 @@ class InnerRequest {
// Start the upgrade in the background.
(async () => {
try {
- // Returns the connection and extra bytes, which we can pass directly to op_ws_server_create
- const upgrade = await op_http_upgrade_next(
+ // Returns the upgraded websocket connection
+ const wsRid = await op_http_upgrade_websocket_next(
slabId,
response.headerList,
);
- const wsRid = op_ws_server_create(upgrade[0], upgrade[1]);
// We have to wait for the go-ahead signal
await goAhead;
diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs
index eaa19a89d..a986de7f3 100644
--- a/ext/http/http_next.rs
+++ b/ext/http/http_next.rs
@@ -29,10 +29,9 @@ use deno_core::OpState;
use deno_core::RcRef;
use deno_core::Resource;
use deno_core::ResourceId;
-use deno_core::ZeroCopyBuf;
use deno_net::ops_tls::TlsStream;
-use deno_net::raw::put_network_stream_resource;
use deno_net::raw::NetworkStream;
+use deno_websocket::ws_create_server_stream;
use fly_accept_encoding::Encoding;
use http::header::ACCEPT_ENCODING;
use http::header::CACHE_CONTROL;
@@ -314,11 +313,11 @@ pub fn op_http_upgrade_raw(
}
#[op]
-pub async fn op_http_upgrade_next(
+pub async fn op_http_upgrade_websocket_next(
state: Rc<RefCell<OpState>>,
index: u32,
headers: Vec<(ByteString, ByteString)>,
-) -> Result<(ResourceId, ZeroCopyBuf), AnyError> {
+) -> Result<ResourceId, AnyError> {
// Stage 1: set the respnse to 101 Switching Protocols and send it
let upgrade = with_http_mut(index, |http| {
// Manually perform the upgrade. We're peeking into hyper's underlying machinery here a bit
@@ -343,17 +342,9 @@ pub async fn op_http_upgrade_next(
// Stage 2: wait for the request to finish upgrading
let upgraded = upgrade.await?;
- // Stage 3: return the extracted raw network stream
+ // Stage 3: take the extracted raw network stream and upgrade it to a websocket, then return it
let (stream, bytes) = extract_network_stream(upgraded);
-
- // We're allocating for those extra bytes, but they are probably going to be empty most of the time
- Ok((
- put_network_stream_resource(
- &mut state.borrow_mut().resource_table,
- stream,
- )?,
- ZeroCopyBuf::from(bytes.to_vec()),
- ))
+ ws_create_server_stream(&mut state.borrow_mut(), stream, bytes)
}
#[op(fast)]
diff --git a/ext/http/lib.rs b/ext/http/lib.rs
index 7a1a93f80..1ed1e60b7 100644
--- a/ext/http/lib.rs
+++ b/ext/http/lib.rs
@@ -116,8 +116,8 @@ deno_core::extension!(
http_next::op_http_set_response_header,
http_next::op_http_set_response_headers,
http_next::op_http_track,
+ http_next::op_http_upgrade_websocket_next,
http_next::op_http_upgrade_raw,
- http_next::op_http_upgrade_next,
http_next::op_http_wait,
],
esm = ["00_serve.js", "01_http.js"],