diff --git a/ext/http/01_http.js b/ext/http/01_http.js index a312cf60ed..b41c36446a 100644 --- a/ext/http/01_http.js +++ b/ext/http/01_http.js @@ -4,11 +4,13 @@ import { core, internals, primordials } from "ext:core/mod.js"; const { BadResourcePrototype, InterruptedPrototype, + internalRidSymbol, } = core; import { op_http_accept, op_http_headers, op_http_shutdown, + op_http_start, op_http_upgrade_websocket, op_http_websocket_accept_header, op_http_write, @@ -71,7 +73,6 @@ import { readableStreamForRid, ReadableStreamPrototype, } from "ext:deno_web/06_streams.js"; -import { serve } from "ext:deno_http/00_serve.js"; import { SymbolDispose } from "ext:deno_web/00_infra.js"; const connErrorSymbol = Symbol("connError"); @@ -557,4 +558,14 @@ function buildCaseInsensitiveCommaValueFinder(checkText) { internals.buildCaseInsensitiveCommaValueFinder = buildCaseInsensitiveCommaValueFinder; -export { _ws, HttpConn, serve, upgradeWebSocket }; +function serveHttp(conn) { + internals.warnOnDeprecatedApi( + "Deno.serveHttp()", + new Error().stack, + "Use `Deno.serve()` instead.", + ); + const rid = op_http_start(conn[internalRidSymbol]); + return new HttpConn(rid, conn.remoteAddr, conn.localAddr); +} + +export { _ws, HttpConn, serveHttp, upgradeWebSocket }; diff --git a/runtime/js/40_http.js b/runtime/js/40_http.js deleted file mode 100644 index 675d428cdf..0000000000 --- a/runtime/js/40_http.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { core, internals } from "ext:core/mod.js"; -import { op_http_start } from "ext:core/ops"; -const { internalRidSymbol } = core; - -import { HttpConn } from "ext:deno_http/01_http.js"; - -function serveHttp(conn) { - internals.warnOnDeprecatedApi( - "Deno.serveHttp()", - new Error().stack, - "Use `Deno.serve()` instead.", - ); - const rid = op_http_start(conn[internalRidSymbol]); - return new HttpConn(rid, conn.remoteAddr, conn.localAddr); -} - -export { serveHttp }; diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 9f403e901e..aa52b0c337 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -13,6 +13,7 @@ import * as console from "ext:deno_console/01_console.js"; import * as ffi from "ext:deno_ffi/00_ffi.js"; import * as net from "ext:deno_net/01_net.js"; import * as tls from "ext:deno_net/02_tls.js"; +import * as serve from "ext:deno_http/00_serve.js"; import * as http from "ext:deno_http/01_http.js"; import * as errors from "ext:runtime/01_errors.js"; import * as version from "ext:runtime/01_version.ts"; @@ -25,8 +26,6 @@ import * as fsEvents from "ext:runtime/40_fs_events.js"; import * as process from "ext:runtime/40_process.js"; import * as signals from "ext:runtime/40_signals.js"; import * as tty from "ext:runtime/40_tty.js"; -// TODO(bartlomieju): this is funky we have two `http` imports -import * as httpRuntime from "ext:runtime/40_http.js"; import * as kv from "ext:deno_kv/01_db.ts"; import * as cron from "ext:deno_cron/01_cron.ts"; import * as webgpuSurface from "ext:deno_webgpu/02_surface.js"; @@ -225,9 +224,8 @@ const denoNs = { permissions: permissions.permissions, Permissions: permissions.Permissions, PermissionStatus: permissions.PermissionStatus, - // TODO(bartlomieju): why is this not in one of extensions? - serveHttp: httpRuntime.serveHttp, - serve: http.serve, + serveHttp: http.serveHttp, + serve: serve.serve, resolveDns: net.resolveDns, upgradeWebSocket: http.upgradeWebSocket, utime: fs.utime, @@ -292,8 +290,6 @@ denoNsUnstableById[unstableIds.fs] = { denoNsUnstableById[unstableIds.http] = { HttpClient: httpClient.HttpClient, createHttpClient: httpClient.createHttpClient, - // TODO(bartlomieju): why is it needed? - http, }; denoNsUnstableById[unstableIds.kv] = { @@ -328,8 +324,6 @@ const denoNsUnstable = { umask: fs.umask, HttpClient: httpClient.HttpClient, createHttpClient: httpClient.createHttpClient, - // TODO(bartlomieju): why is it needed? - http, dlopen: ffi.dlopen, UnsafeCallback: ffi.UnsafeCallback, UnsafePointer: ffi.UnsafePointer, diff --git a/runtime/shared.rs b/runtime/shared.rs index 946f33c6fb..61f9ca2250 100644 --- a/runtime/shared.rs +++ b/runtime/shared.rs @@ -45,7 +45,6 @@ extension!(runtime, "13_buffer.js", "30_os.js", "40_fs_events.js", - "40_http.js", "40_process.js", "40_signals.js", "40_tty.js", diff --git a/tests/testdata/run/unstable_http.disabled.out b/tests/testdata/run/unstable_http.disabled.out index 6eb83832e1..3562f72fdd 100644 --- a/tests/testdata/run/unstable_http.disabled.out +++ b/tests/testdata/run/unstable_http.disabled.out @@ -1,12 +1,4 @@ main undefined main undefined -main undefined -main undefined -main undefined -main undefined -worker undefined -worker undefined -worker undefined -worker undefined worker undefined worker undefined diff --git a/tests/testdata/run/unstable_http.enabled.out b/tests/testdata/run/unstable_http.enabled.out index 4f3c656253..f7aa776e9e 100644 --- a/tests/testdata/run/unstable_http.enabled.out +++ b/tests/testdata/run/unstable_http.enabled.out @@ -1,12 +1,4 @@ main [class HttpClient] main [Function: createHttpClient] -main [class HttpConn] -main Symbol("[[associated_ws]]") -main [Function: serve] -main [Function: upgradeWebSocket] worker [class HttpClient] worker [Function: createHttpClient] -worker [class HttpConn] -worker Symbol("[[associated_ws]]") -worker [Function: serve] -worker [Function: upgradeWebSocket] diff --git a/tests/testdata/run/unstable_http.js b/tests/testdata/run/unstable_http.js index 1a3ddb2d3a..7ad09aec57 100644 --- a/tests/testdata/run/unstable_http.js +++ b/tests/testdata/run/unstable_http.js @@ -2,10 +2,6 @@ const scope = import.meta.url.slice(-7) === "#worker" ? "worker" : "main"; console.log(scope, Deno.HttpClient); console.log(scope, Deno.createHttpClient); -console.log(scope, Deno.http?.HttpConn); -console.log(scope, Deno.http?._ws); -console.log(scope, Deno.http?.serve); -console.log(scope, Deno.http?.upgradeWebSocket); if (scope === "worker") { postMessage("done"); diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts index c33503bdfc..3202d40fa7 100644 --- a/tests/unit/fetch_test.ts +++ b/tests/unit/fetch_test.ts @@ -1249,44 +1249,16 @@ Deno.test({}, function fetchWritableRespProps() { Deno.test( { permissions: { net: true } }, - async function fetchFilterOutCustomHostHeader(): Promise< - void - > { + async function fetchFilterOutCustomHostHeader() { const addr = `127.0.0.1:${listenPort}`; - const [hostname, port] = addr.split(":"); - const listener = Deno.listen({ - hostname, - port: Number(port), - }) as Deno.Listener; - - let httpConn: Deno.HttpConn; - listener.accept().then(async (conn: Deno.Conn) => { - httpConn = Deno.serveHttp(conn); - - await httpConn.nextRequest() - .then(async (requestEvent: Deno.RequestEvent | null) => { - const hostHeader = requestEvent?.request.headers.get("Host"); - const headersToReturn = hostHeader - ? { "Host": hostHeader } - : undefined; - - await requestEvent?.respondWith( - new Response("", { - status: 200, - headers: headersToReturn, - }), - ); - }); + const server = Deno.serve({ port: listenPort }, (req) => { + return new Response(`Host header was ${req.headers.get("Host")}`); }); - const response = await fetch(`http://${addr}/`, { headers: { "Host": "example.com" }, }); - await response.text(); - listener.close(); - httpConn!.close(); - - assertEquals(response.headers.get("Host"), addr); + assertEquals(await response.text(), `Host header was ${addr}`); + await server.shutdown(); }, ); diff --git a/tools/core_import_map.json b/tools/core_import_map.json index 078808aa0d..463095de8a 100644 --- a/tools/core_import_map.json +++ b/tools/core_import_map.json @@ -237,7 +237,6 @@ "ext:runtime/13_buffer.js": "../runtime/js/13_buffer.js", "ext:runtime/30_os.js": "../runtime/js/30_os.js", "ext:runtime/40_fs_events.js": "../runtime/js/40_fs_events.js", - "ext:runtime/40_http.js": "../runtime/js/40_http.js", "ext:runtime/40_process.js": "../runtime/js/40_process.js", "ext:runtime/40_signals.js": "../runtime/js/40_signals.js", "ext:runtime/40_tty.js": "../runtime/js/40_tty.js",