puma / puma

A Ruby/Rack web server built for parallelism

Home Page:https://puma.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Listen for HTTP and HTTPS on the same port, redirecting clients to HTTPS for easier local development

nogweii opened this issue · comments

Is your feature request related to a problem? Please describe.
This is possibly a too-crazy idea, but wanted to present it for feedback. A server can easily distinguish between plain-text & encrypted incoming clients, since the leading bytes of an attempted TLS connection are different than an HTTP connection.

I like using the localhost gem to provide an HTTPS certificate in development environments. I occasionally get an HTTP URL for localhost from a tool or library that is unaware. Clicking on that link results in an eventual timeout as Puma will never respond to a plain text connection when it only has been bound to ssl://... URIs. I then fix the URL and continue on, but it'd be nice to fix that papercut.

Describe the solution you'd like
Puma listens for incoming unencrypted HTTP clients on the same port as HTTPS clients, and returns an HTTP 308 to the same port & path, but with an HTTPS scheme.

Describe alternatives you've considered
Fix/configure all of the libraries to know I have an HTTPS cert for localhost. Working on it, but this would be a neat backup option in case something gets overlooked.

Additional context
I'd assume this would be an opt-in behavior. Possibly automatically turned on if the localhost gem is detected.

I'm gonna say wontfix. Easiest fix for this papercut locally is to use a reverse proxy and listen to both http/https.

If I get it to work, would you accept a PR that does some automatic configuration akin to how localhost is integrated?

I think it is hard to answer that now, better if you put up a PR with the changes required when you get there, and it can be judged based on that.

Maybe it could be a Puma plugin? Similar to puma-acme that recently surfaced (#3301, #3302)