Redirect http to https #3105
-
Hello, I saw following discussion: I have a similar request, but the problem is that I have the web server listening https on a custom port, so I cannot use port 80 with its event handler to redirect and port 443 is not used for https. How can redirect a request http from the browser to https in this case ? maybe using mg_url_is_ssl() to know if the browser request is http or https and manage this in the event handler ? I am using Mongoose version 7.16 Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Let me see IIUC. |
Beta Was this translation helpful? Give feedback.
Let me see IIUC.
You have a listener that expects HTTPS, that is, it is ready to call mg_tls_init() on connect and will initiate/process a TLS handshake after that, and handle incoming data over TCP as TLS records.
You want that listener to "guess" that what is coming is not a TLS handshake or a TLS record but an HTTP message.
I don't see such a thing is possible. mg_url_is_ssl() does not work on the request, it works on the URL you pass as an argument, it can't whatsoever know if the browser request is HTTP or HTTPS, because there is no such thing as "an HTTPS request", HTTPS is just HTTP over TLS, so you first start a TLS encrypted pipe, then send HTTP over that pipe. You would need to …