@@ -16,10 +16,10 @@ type RedirectConfig struct {
16
16
Code int `yaml:"code"`
17
17
}
18
18
19
- // redirectLogic represents a function that given a tls flag , host and uri
19
+ // redirectLogic represents a function that given a scheme , host and uri
20
20
// can both: 1) determine if redirect is needed (will set ok accordingly) and
21
21
// 2) return the appropriate redirect url.
22
- type redirectLogic func (tls bool , scheme , host , uri string ) (ok bool , url string )
22
+ type redirectLogic func (scheme , host , uri string ) (ok bool , url string )
23
23
24
24
const www = "www"
25
25
@@ -40,8 +40,8 @@ func HTTPSRedirect() echo.MiddlewareFunc {
40
40
// HTTPSRedirectWithConfig returns an HTTPSRedirect middleware with config.
41
41
// See `HTTPSRedirect()`.
42
42
func HTTPSRedirectWithConfig (config RedirectConfig ) echo.MiddlewareFunc {
43
- return redirect (config , func (tls bool , _ , host , uri string ) (ok bool , url string ) {
44
- if ok = ! tls ; ok {
43
+ return redirect (config , func (scheme , host , uri string ) (ok bool , url string ) {
44
+ if ok = scheme != "https" ; ok {
45
45
url = "https://" + host + uri
46
46
}
47
47
return
@@ -59,8 +59,8 @@ func HTTPSWWWRedirect() echo.MiddlewareFunc {
59
59
// HTTPSWWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
60
60
// See `HTTPSWWWRedirect()`.
61
61
func HTTPSWWWRedirectWithConfig (config RedirectConfig ) echo.MiddlewareFunc {
62
- return redirect (config , func (tls bool , _ , host , uri string ) (ok bool , url string ) {
63
- if ok = ! tls && host [:3 ] != www ; ok {
62
+ return redirect (config , func (scheme , host , uri string ) (ok bool , url string ) {
63
+ if ok = scheme != "https" && host [:3 ] != www ; ok {
64
64
url = "https://www." + host + uri
65
65
}
66
66
return
@@ -78,8 +78,8 @@ func HTTPSNonWWWRedirect() echo.MiddlewareFunc {
78
78
// HTTPSNonWWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
79
79
// See `HTTPSNonWWWRedirect()`.
80
80
func HTTPSNonWWWRedirectWithConfig (config RedirectConfig ) echo.MiddlewareFunc {
81
- return redirect (config , func (tls bool , _ , host , uri string ) (ok bool , url string ) {
82
- if ok = ! tls ; ok {
81
+ return redirect (config , func (scheme , host , uri string ) (ok bool , url string ) {
82
+ if ok = scheme != "https" ; ok {
83
83
if host [:3 ] == www {
84
84
host = host [4 :]
85
85
}
@@ -100,7 +100,7 @@ func WWWRedirect() echo.MiddlewareFunc {
100
100
// WWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
101
101
// See `WWWRedirect()`.
102
102
func WWWRedirectWithConfig (config RedirectConfig ) echo.MiddlewareFunc {
103
- return redirect (config , func (_ bool , scheme , host , uri string ) (ok bool , url string ) {
103
+ return redirect (config , func (scheme , host , uri string ) (ok bool , url string ) {
104
104
if ok = host [:3 ] != www ; ok {
105
105
url = scheme + "://www." + host + uri
106
106
}
@@ -119,7 +119,7 @@ func NonWWWRedirect() echo.MiddlewareFunc {
119
119
// NonWWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
120
120
// See `NonWWWRedirect()`.
121
121
func NonWWWRedirectWithConfig (config RedirectConfig ) echo.MiddlewareFunc {
122
- return redirect (config , func (tls bool , scheme , host , uri string ) (ok bool , url string ) {
122
+ return redirect (config , func (scheme , host , uri string ) (ok bool , url string ) {
123
123
if ok = host [:3 ] == www ; ok {
124
124
url = scheme + "://" + host [4 :] + uri
125
125
}
@@ -143,7 +143,7 @@ func redirect(config RedirectConfig, cb redirectLogic) echo.MiddlewareFunc {
143
143
144
144
req , scheme := c .Request (), c .Scheme ()
145
145
host := req .Host
146
- if ok , url := cb (c . IsTLS (), scheme , host , req .RequestURI ); ok {
146
+ if ok , url := cb (scheme , host , req .RequestURI ); ok {
147
147
return c .Redirect (config .Code , url )
148
148
}
149
149
0 commit comments