forked from makazeu/AnotherSteamCommunityFix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp302.go
More file actions
44 lines (38 loc) · 814 Bytes
/
Copy pathhttp302.go
File metadata and controls
44 lines (38 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package AnotherSteamCommunityFix
import (
"net"
"net/http"
)
func redirectHTTPS(w http.ResponseWriter, req *http.Request) {
target := "https://" + req.Host + req.URL.Path
if len(req.URL.RawQuery) > 0 {
target += "?" + req.URL.RawQuery
}
http.Redirect(w, req, target, http.StatusFound)
}
func StartServingHTTPSRedirect() {
server := &Server{
http.Server{
Addr: ":80",
Handler: http.HandlerFunc(redirectHTTPS),
},
}
fatalLogger.Fatal(server.ListenAndServe())
}
type Server struct {
http.Server
}
func (srv *Server) ListenAndServe() error {
addr := srv.Addr
if addr == "" {
addr = ":http"
}
ln, err := net.Listen("tcp4", addr)
if err != nil {
return err
}
return srv.Serve(tcpKeepAliveListener{ln.(*net.TCPListener)})
}
type tcpKeepAliveListener struct {
*net.TCPListener
}