oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.51k stars 2.79k forks source link

Document `socket.upgradeTLS` #2809

Open samuelgozi opened 1 year ago

samuelgozi commented 1 year ago

What is the problem this feature would solve?

I would like to implement an HTTPS proxy server using bun, however there are some primitives missing.

What is the feature you are proposing to solve the problem?

  1. Function to upgrade a TCP connection to TLS over TCP.
  2. Expose HTTP parser, or server so that a TCP/TLS connection can be passed into it instead of listening to a port.

What alternatives have you considered?

I have already implemented this in Node.js, then tried Bun and Deno. Bun and Deno lack the same primitives.

I am currently considering implementing this in a lower level language such as Rust and then provide bindings to node or access through FFI.

GrzegorzManiak commented 1 year ago

Still nothing in Bun v1.0.7

Jarred-Sumner commented 1 year ago

Upgrading from a TCP connection -> TLS connection is supported as of Bun v0.6.13 (July of 2023). This is not supported on the HTTP server yet.

It is missing documentation though (cc @colinhacks @cirospaciari)

const tlsSocket = socket.upgradeTLS({
  // .data on the newly created socket
  data: myData,
  tls: {
    // tls options same as Bun.connect / Bun.listen
  },
  socket: {
    // socket options same as Bun.connect / Bun.listen
  }
});
GrzegorzManiak commented 1 year ago

Thanks!

samuelgozi commented 1 year ago

Thanks, thats awesome! Can hopefully migrate my project now (didn't test it yet). The HTTP parse would help but is not a requirement, it can be implemented in JS/TS.