/
request_redirect_https.go
43 lines (38 loc) · 1.09 KB
/
request_redirect_https.go
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
package teaproxy
import (
"net"
"net/http"
)
func (this *Request) callRedirectToHttps(writer *ResponseWriter) {
// 是否需要跳转到HTTPS
if this.redirectToHttps && this.rawScheme == "http" {
host := this.raw.Host
host1, _, err := net.SplitHostPort(host)
if err == nil {
host = host1
}
// 是否有HTTPS
if this.server.SSL != nil && this.server.SSL.On && len(this.server.SSL.Listen) > 0 {
listen := this.server.SSL.Listen[0]
_, port, err := net.SplitHostPort(listen)
if err == nil {
if port == "443" {
u := "https://" + host + this.raw.RequestURI
http.Redirect(writer, this.raw, u, http.StatusTemporaryRedirect)
return
} else {
u := "https://" + host + ":" + port + this.raw.RequestURI
http.Redirect(writer, this.raw, u, http.StatusTemporaryRedirect)
return
}
} else {
u := "https://" + host + this.raw.RequestURI
http.Redirect(writer, this.raw, u, http.StatusTemporaryRedirect)
return
}
}
u := "https://" + host + this.raw.RequestURI
http.Redirect(writer, this.raw, u, http.StatusTemporaryRedirect)
return
}
}