Samuel
Samuel2y ago

Reading a ReadabeStream without consuming it?

Hi, I'm trying to migrate an HTTP/HTTPS proxy protocol server from Node.js to Deno. The proxy listens for TCP connections, and I need to handle HTTP and HTTPS connections differently, so the first think I do is to read the first byte of every new connection to determine if it starts with "22" (which means that it is a TLS handshake). If it is a TLS handshake I handle that one way, else i just pass it to an HTTP parser. The problem is that If i read the first byte then I cant pass the connection to Deno.serveHttp (?) because the first chunk was consumed already. Is it possible to "peek" into a Deno.Conn / ReadableStream without consuming it, so that the Conn instance can be used elsewhere?
3 Replies
AapoAlas
AapoAlas2y ago
You can tee the stream, effectively copying it.
Samuel
SamuelOP2y ago
But If I tee it, can I still use the one in the original connection? Because I would like to pass the connection later to Deno.serveHttp(conn)
AapoAlas
AapoAlas2y ago
Hmm.... Not sure. Probably not.

Did you find this page helpful?