diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-22 22:35:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-22 21:35:39 +0000 |
commit | 71551c80a1c7ea2cc75cf82c5871212559709789 (patch) | |
tree | 6d5e458e54ea6598d78d6b4d7177006a9048deb6 /cli | |
parent | 69d5f136badfd7cfa9b979ff2fee7caf397098ca (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 'cli')
-rw-r--r-- | cli/tests/integration/lsp_tests.rs | 292 | ||||
-rw-r--r-- | cli/tests/testdata/run/unstable_http.disabled.out | 4 | ||||
-rw-r--r-- | cli/tests/testdata/run/unstable_http.enabled.out | 4 | ||||
-rw-r--r-- | cli/tests/testdata/run/unstable_http.js | 2 | ||||
-rw-r--r-- | cli/tests/unit/http_test.ts | 157 | ||||
-rw-r--r-- | cli/tsc/99_main_compiler.js | 1 | ||||
-rw-r--r-- | cli/tsc/dts/lib.deno.unstable.d.ts | 28 |
7 files changed, 41 insertions, 447 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 2fc3d29e8..ba44c670d 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -9059,12 +9059,27 @@ fn lsp_workspace_symbol() { "text": "export class B {\n fieldC: string;\n fieldD: string;\n}\n", } })); - let res = client.write_request( + let mut res = client.write_request( "workspace/symbol", json!({ "query": "field" }), ); + + // Replace `range` fields with `null` values. These are not important + // for assertion and require to be updated if we change unstable APIs. + for obj in res.as_array_mut().unwrap().iter_mut() { + *obj + .as_object_mut() + .unwrap() + .get_mut("location") + .unwrap() + .as_object_mut() + .unwrap() + .get_mut("range") + .unwrap() = Value::Null; + } + assert_eq!( res, json!([ @@ -9073,16 +9088,7 @@ fn lsp_workspace_symbol() { "kind": 8, "location": { "uri": "file:///a/file.ts", - "range": { - "start": { - "line": 1, - "character": 2 - }, - "end": { - "line": 1, - "character": 17 - } - } + "range": null, }, "containerName": "A" }, @@ -9091,16 +9097,7 @@ fn lsp_workspace_symbol() { "kind": 8, "location": { "uri": "file:///a/file.ts", - "range": { - "start": { - "line": 2, - "character": 2 - }, - "end": { - "line": 2, - "character": 17 - } - } + "range": null, }, "containerName": "A" }, @@ -9109,16 +9106,7 @@ fn lsp_workspace_symbol() { "kind": 8, "location": { "uri": "file:///a/file_01.ts", - "range": { - "start": { - "line": 1, - "character": 2 - }, - "end": { - "line": 1, - "character": 17 - } - } + "range": null, }, "containerName": "B" }, @@ -9127,16 +9115,7 @@ fn lsp_workspace_symbol() { "kind": 8, "location": { "uri": "file:///a/file_01.ts", - "range": { - "start": { - "line": 2, - "character": 2 - }, - "end": { - "line": 2, - "character": 17 - } - } + "range": null, }, "containerName": "B" }, @@ -9145,16 +9124,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3165, - "character": 4 - }, - "end": { - "line": 3165, - "character": 55 - } - } + "range": null, }, "containerName": "CalendarProtocol" }, @@ -9163,16 +9133,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3335, - "character": 4 - }, - "end": { - "line": 3335, - "character": 47 - } - } + "range": null, }, "containerName": "Calendar" }, @@ -9181,16 +9142,7 @@ fn lsp_workspace_symbol() { "kind": 11, "location": { "uri": "deno:/asset/lib.decorators.d.ts", - "range": { - "start": { - "line": 343, - "character": 0 - }, - "end": { - "line": 385, - "character": 1 - } - } + "range": null, }, "containerName": "" }, @@ -9199,16 +9151,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3143, - "character": 4 - }, - "end": { - "line": 3146, - "character": 26 - } - } + "range": null, }, "containerName": "CalendarProtocol" }, @@ -9217,16 +9160,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3313, - "character": 4 - }, - "end": { - "line": 3316, - "character": 26 - } - } + "range": null, }, "containerName": "Calendar" }, @@ -9235,16 +9169,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3439, - "character": 4 - }, - "end": { - "line": 3439, - "character": 39 - } - } + "range": null, }, "containerName": "PlainDate" }, @@ -9253,16 +9178,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3602, - "character": 4 - }, - "end": { - "line": 3602, - "character": 43 - } - } + "range": null, }, "containerName": "PlainDateTime" }, @@ -9271,16 +9187,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3651, - "character": 4 - }, - "end": { - "line": 3651, - "character": 39 - } - } + "range": null, }, "containerName": "PlainMonthDay" }, @@ -9289,16 +9196,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3770, - "character": 4 - }, - "end": { - "line": 3770, - "character": 39 - } - } + "range": null, }, "containerName": "PlainTime" }, @@ -9307,16 +9205,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3923, - "character": 4 - }, - "end": { - "line": 3923, - "character": 39 - } - } + "range": null, }, "containerName": "PlainYearMonth" }, @@ -9325,16 +9214,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 4082, - "character": 4 - }, - "end": { - "line": 4082, - "character": 43 - } - } + "range": null, }, "containerName": "ZonedDateTime" }, @@ -9343,16 +9223,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3166, - "character": 4 - }, - "end": { - "line": 3169, - "character": 31 - } - } + "range": null, }, "containerName": "CalendarProtocol" }, @@ -9361,16 +9232,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3336, - "character": 4 - }, - "end": { - "line": 3339, - "character": 31 - } - } + "range": null, }, "containerName": "Calendar" }, @@ -9379,16 +9241,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3151, - "character": 4 - }, - "end": { - "line": 3154, - "character": 30 - } - } + "range": null, }, "containerName": "CalendarProtocol" }, @@ -9397,16 +9250,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3321, - "character": 4 - }, - "end": { - "line": 3324, - "character": 30 - } - } + "range": null, }, "containerName": "Calendar" }, @@ -9415,16 +9259,7 @@ fn lsp_workspace_symbol() { "kind": 5, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3355, - "character": 2 - }, - "end": { - "line": 3360, - "character": 4 - } - } + "range": null, }, "containerName": "Temporal" }, @@ -9433,16 +9268,7 @@ fn lsp_workspace_symbol() { "kind": 5, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3466, - "character": 2 - }, - "end": { - "line": 3477, - "character": 4 - } - } + "range": null, }, "containerName": "Temporal" }, @@ -9451,16 +9277,7 @@ fn lsp_workspace_symbol() { "kind": 5, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3671, - "character": 2 - }, - "end": { - "line": 3678, - "character": 4 - } - } + "range": null, }, "containerName": "Temporal" }, @@ -9469,16 +9286,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3147, - "character": 4 - }, - "end": { - "line": 3150, - "character": 31 - } - } + "range": null, }, "containerName": "CalendarProtocol" }, @@ -9487,16 +9295,7 @@ fn lsp_workspace_symbol() { "kind": 6, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3317, - "character": 4 - }, - "end": { - "line": 3320, - "character": 31 - } - } + "range": null, }, "containerName": "Calendar" }, @@ -9505,16 +9304,7 @@ fn lsp_workspace_symbol() { "kind": 5, "location": { "uri": "deno:/asset/lib.deno.unstable.d.ts", - "range": { - "start": { - "line": 3952, - "character": 2 - }, - "end": { - "line": 3965, - "character": 4 - } - } + "range": null, }, "containerName": "Temporal" } diff --git a/cli/tests/testdata/run/unstable_http.disabled.out b/cli/tests/testdata/run/unstable_http.disabled.out index 63a6c83c5..6eb83832e 100644 --- a/cli/tests/testdata/run/unstable_http.disabled.out +++ b/cli/tests/testdata/run/unstable_http.disabled.out @@ -4,10 +4,6 @@ main undefined main undefined main undefined main undefined -main undefined -main undefined -worker undefined -worker undefined worker undefined worker undefined worker undefined diff --git a/cli/tests/testdata/run/unstable_http.enabled.out b/cli/tests/testdata/run/unstable_http.enabled.out index 558f1f542..4f3c65625 100644 --- a/cli/tests/testdata/run/unstable_http.enabled.out +++ b/cli/tests/testdata/run/unstable_http.enabled.out @@ -3,14 +3,10 @@ main [Function: createHttpClient] main [class HttpConn] main Symbol("[[associated_ws]]") main [Function: serve] -main [Function: upgradeHttp] main [Function: upgradeWebSocket] -main [Function: upgradeHttp] worker [class HttpClient] worker [Function: createHttpClient] worker [class HttpConn] worker Symbol("[[associated_ws]]") worker [Function: serve] -worker [Function: upgradeHttp] worker [Function: upgradeWebSocket] -worker [Function: upgradeHttp] diff --git a/cli/tests/testdata/run/unstable_http.js b/cli/tests/testdata/run/unstable_http.js index 012519657..1a3ddb2d3 100644 --- a/cli/tests/testdata/run/unstable_http.js +++ b/cli/tests/testdata/run/unstable_http.js @@ -5,9 +5,7 @@ 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?.upgradeHttp); console.log(scope, Deno.http?.upgradeWebSocket); -console.log(scope, Deno.upgradeHttp); if (scope === "worker") { postMessage("done"); diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts index 7d1f8997d..bd4c8da09 100644 --- a/cli/tests/unit/http_test.ts +++ b/cli/tests/unit/http_test.ts @@ -1,7 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { Buffer, BufReader, BufWriter } from "../../../test_util/std/io/mod.ts"; import { TextProtoReader } from "../testdata/run/textproto.ts"; -import { serve, serveTls } from "../../../test_util/std/http/server.ts"; import { assert, assertEquals, @@ -2181,162 +2180,6 @@ Deno.test({ }, }); -Deno.test("upgradeHttp tcp", async () => { - async function client() { - const tcpConn = await Deno.connect({ port: listenPort }); - await tcpConn.write( - new TextEncoder().encode( - "CONNECT server.example.com:80 HTTP/1.1\r\n\r\nbla bla bla\nbla bla\nbla\n", - ), - ); - setTimeout(async () => { - await tcpConn.write( - new TextEncoder().encode( - "bla bla bla\nbla bla\nbla\n", - ), - ); - tcpConn.close(); - }, 500); - } - - const abortController = new AbortController(); - const signal = abortController.signal; - - const server = serve((req) => { - const p = Deno.upgradeHttp(req); - - (async () => { - const [conn, firstPacket] = await p; - const buf = new Uint8Array(1024); - const firstPacketText = new TextDecoder().decode(firstPacket); - assertEquals(firstPacketText, "bla bla bla\nbla bla\nbla\n"); - const n = await conn.read(buf); - assert(n != null); - const secondPacketText = new TextDecoder().decode(buf.slice(0, n)); - assertEquals(secondPacketText, "bla bla bla\nbla bla\nbla\n"); - abortController.abort(); - conn.close(); - })(); - - return new Response(null, { status: 101 }); - }, { port: listenPort, signal }); - - await Promise.all([server, client()]); -}); - -Deno.test( - "upgradeHttp tls", - { permissions: { net: true, read: true } }, - async () => { - async function client() { - const caCerts = [ - await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"), - ]; - const tlsConn = await Deno.connectTls({ - hostname: "localhost", - port: listenPort, - caCerts, - }); - await tlsConn.write( - new TextEncoder().encode( - "CONNECT server.example.com:80 HTTP/1.1\r\n\r\nbla bla bla\nbla bla\nbla\n", - ), - ); - setTimeout(async () => { - await tlsConn.write( - new TextEncoder().encode( - "bla bla bla\nbla bla\nbla\n", - ), - ); - tlsConn.close(); - }, 500); - } - - const abortController = new AbortController(); - const signal = abortController.signal; - const certFile = "cli/tests/testdata/tls/localhost.crt"; - const keyFile = "cli/tests/testdata/tls/localhost.key"; - - const server = serveTls((req) => { - const p = Deno.upgradeHttp(req); - - (async () => { - const [conn, firstPacket] = await p; - const buf = new Uint8Array(1024); - const firstPacketText = new TextDecoder().decode(firstPacket); - assertEquals(firstPacketText, "bla bla bla\nbla bla\nbla\n"); - const n = await conn.read(buf); - assert(n != null); - const secondPacketText = new TextDecoder().decode(buf.slice(0, n)); - assertEquals(secondPacketText, "bla bla bla\nbla bla\nbla\n"); - abortController.abort(); - conn.close(); - })(); - - return new Response(null, { status: 101 }); - }, { hostname: "localhost", port: listenPort, signal, keyFile, certFile }); - - await Promise.all([server, client()]); - }, -); - -Deno.test("upgradeHttp unix", { - permissions: { read: true, write: true }, - ignore: Deno.build.os === "windows", -}, async () => { - const filePath = tmpUnixSocketPath(); - const { promise, resolve } = Promise.withResolvers<void>(); - - async function client() { - const unixConn = await Deno.connect({ path: filePath, transport: "unix" }); - await unixConn.write( - new TextEncoder().encode( - "CONNECT server.example.com:80 HTTP/1.1\r\n\r\nbla bla bla\nbla bla\nbla\n", - ), - ); - setTimeout(async () => { - await unixConn.write( - new TextEncoder().encode( - "bla bla bla\nbla bla\nbla\n", - ), - ); - unixConn.close(); - resolve(); - }, 500); - await promise; - } - - const server = (async () => { - const listener = Deno.listen({ path: filePath, transport: "unix" }); - const conn = await listener.accept(); - listener.close(); - const httpConn = Deno.serveHttp(conn); - const reqEvent = await httpConn.nextRequest(); - assert(reqEvent); - const { request, respondWith } = reqEvent; - const p = Deno.upgradeHttp(request); - - const promise = (async () => { - const [conn, firstPacket] = await p; - const buf = new Uint8Array(1024); - const firstPacketText = new TextDecoder().decode(firstPacket); - assertEquals(firstPacketText, "bla bla bla\nbla bla\nbla\n"); - const n = await conn.read(buf); - assert(n != null); - const secondPacketText = new TextDecoder().decode(buf.slice(0, n)); - assertEquals(secondPacketText, "bla bla bla\nbla bla\nbla\n"); - conn.close(); - })(); - - const resp = new Response(null, { status: 101 }); - await respondWith(resp); - await promise; - httpConn!.close(); - })(); - - await Promise.all([server, client()]); -}); - Deno.test( { permissions: { net: true } }, async function httpServerReadLargeBodyWithContentLength() { diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 0cb917f96..32c3bf035 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -53,7 +53,6 @@ delete Object.prototype.__proto__; "listen", "listenDatagram", "openKv", - "upgradeHttp", "umask", ]); const unstableMsgSuggestion = diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index f0f6f4571..870cb2e1a 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -1189,34 +1189,6 @@ declare namespace Deno { /** **UNSTABLE**: New API, yet to be vetted. * - * Allows "hijacking" the connection that the request is associated with. This - * can be used to implement protocols that build on top of HTTP (eg. - * {@linkcode WebSocket}). - * - * The returned promise returns underlying connection and first packet - * received. The promise shouldn't be awaited before responding to the - * `request`, otherwise event loop might deadlock. - * - * ```ts - * function handler(req: Request): Response { - * Deno.upgradeHttp(req).then(([conn, firstPacket]) => { - * // ... - * }); - * return new Response(null, { status: 101 }); - * } - * ``` - * - * This method can only be called on requests originating the - * {@linkcode Deno.serveHttp} server. - * - * @category HTTP Server - */ - export function upgradeHttp( - request: Request, - ): Promise<[Deno.Conn, Uint8Array]>; - - /** **UNSTABLE**: New API, yet to be vetted. - * * Open a new {@linkcode Deno.Kv} connection to persist data. * * When a path is provided, the database will be persisted to disk at that |