Skip to content

Commit

Permalink
add <meta> refresh
Browse files Browse the repository at this point in the history
an additional fallback, as the mission for this project remains
to implement pretty much every standard way of https upgrading
  • Loading branch information
pixelcmtd committed Aug 15, 2023
1 parent b527fc2 commit 4239466
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion redirector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
_ "embed"
"fmt"
"html"
"net/http"
"net/url"
"strings"
Expand All @@ -29,13 +30,15 @@ func main() {

cm3.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
totalReqs.WithLabelValues().Inc()
refresh := ""
if strings.Contains(r.Host, ".") && !strings.Contains(r.Host, ":") {
var url = url.URL{Host: r.Host, Scheme: "https", Path: r.URL.Path}
w.Header().Add("Location", url.String())
w.WriteHeader(301)
hostReqs.WithLabelValues().Inc()
refresh = "<meta http-equiv=\"refresh\" content=\"0;url=" + html.EscapeString(url.String()) + "\"/>"
}
fmt.Fprintf(w, response)
fmt.Fprintf(w, response, refresh)
})

cm3.ListenAndServeHttp(":80", nil)
Expand Down
10 changes: 8 additions & 2 deletions response.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
<head>
<title>Redirecting...</title>
<script>window.location.protocol = 'https:';</script>
%s
</head>
<body>
Just switch to https up there ↑
<body style="font-size: large;">
<p>
This site is only available over HTTPS, please use that.
</p>
<noscript>
Since you don't have JavaScript enabled, we might not be able to redirect you.
</noscript>
</body>
</html>
2 changes: 1 addition & 1 deletion response.min.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><title>Redirecting...</title><script>window.location.protocol="https:"</script></head><body>Just switch to https up there ↑</body></html>
<!doctype html><html lang="en"><head><title>Redirecting...</title><script>window.location.protocol="https:"</script>%s</head><body style="font-size:large"><p>This site is only available over HTTPS, please use that.</p><noscript>Since you don't have JavaScript enabled, we might not be able to redirect you.</noscript></body></html>

0 comments on commit 4239466

Please sign in to comment.