-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(unstable): Add Deno.upgradeHttp API #13618
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not very happy with this API. It isn't going to work well in std/http
.
@lucacasonato its very WIP still |
My preferred API: const reqEvent = await httpConn.nextRequest();
if (!e) return;
const [conn, readBuf]: [Conn, Uint8Array] = await reqEvent.upgradeWith(new Response(null));
I'm sure there's away to add support for this to |
Ideally something like this: export interface RawUpgrade {
response: Response;
conn: Promise<Deno.Conn | Deno.TlsConn>;
}
export function upgradeRaw(): RawUpgrade; example: async function server() {
let tcp_server = Deno.listen({ host: "127.0.0.1", port: 8080 });
let tcp_conn = await tcp_server.accept();
let http_conn = Deno.serveHttp(tcp_conn);
let http_event = await http_conn.nextRequest();
const { connPromise, response } = Deno.upgradeRaw({ status: 101 });
http_event.respondWith(response);
let [conn, firstPacket] = await connPromise; // its Deno.Conn or Deno.TlsConn
} |
We've discussed this and came up with this API import { serve } from "https://deno.land/std/http/server.ts";
serve((req) => {
let p = Deno.upgradeHttp(req);
(async () {
let [conn, firstPacket] = await p;
// ...
})();
// this would hang forever. don't do the following:
// await p;
return new Response({ status: 101 });
}); |
I think the In that case, we don't need to deal with the difference between tcp/uds connections and it's tls wrapped, and we don't need the first-packet |
We cant return return Upgrade directly; we'd need to create some new class then on JS side for that. Also being able to differentiate if it is tcp or tls means different functionality can be used (as in, tcp has some methods that tls doesnt). API wise this is just the best. |
Ok, the original structure has more control, come on |
|
This reverts commit b9753de.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Err(_) => Err(custom_error( | ||
"Http", | ||
"encountered unsupported transport while upgrading", | ||
)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we also support Unix transport?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we do...
fixes #12718