Skip to content

Console: redirect plain HTTP to HTTPS on a TLS port - #2

Merged
jthy10 merged 1 commit into
mainfrom
https-redirect
Oct 16, 2026
Merged

jthy10 merged 1 commit into
mainfrom
https-redirect

Conversation

@jthy10

@jthy10 jthy10 commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Reported from testing v1.4.0 on a phone: entering 192.168.x.x:8787 without https:// showed Go's "Client sent an HTTP request to an HTTPS server" error, because phone browsers try plain HTTP first.

What changes

  • When the console serves HTTPS (LAN access on, or -tls-self-signed/-tls-cert), its listener peeks at the first byte of each connection. A TLS handshake (0x16) goes to the console as before. Anything else goes to a small server that answers with a 302 redirect to https://<same host><same path>.
  • The redirect is temporary on purpose: if LAN access is turned off later, the local browser won't remember a redirect to an HTTPS port that no longer exists.
  • The redirect server is closed together with the console when it moves or shuts down.

Testing

TestSelfSignedTLS now checks that plain HTTP on the TLS port returns a 302 with the right Location (path and query kept), and that HTTPS still serves the dashboard.

Typing 192.168.1.50:8787 into a phone tries http:// first, and with LAN
access on (or -tls-self-signed) Go answered with "Client sent an HTTP
request to an HTTPS server". The listener now looks at the first byte
of each connection: TLS handshakes go to the console, anything else
gets a temporary redirect to the same address over https://.
@jthy10
jthy10 merged commit afb315e into main Oct 16, 2026
5 checks passed
@jthy10
jthy10 deleted the https-redirect branch October 16, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant