mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
fixed redirectHTTP middleware
This commit is contained in:
parent
f8bdc7044c
commit
51f9afb471
1 changed files with 7 additions and 1 deletions
|
@ -2,6 +2,7 @@ package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
)
|
)
|
||||||
|
@ -10,7 +11,12 @@ var RedirectHTTP = &Middleware{
|
||||||
before: func(next http.HandlerFunc, w ResponseWriter, r *Request) {
|
before: func(next http.HandlerFunc, w ResponseWriter, r *Request) {
|
||||||
if r.TLS == nil {
|
if r.TLS == nil {
|
||||||
r.URL.Scheme = "https"
|
r.URL.Scheme = "https"
|
||||||
r.URL.Host = r.URL.Hostname() + ":" + common.ProxyHTTPSPort
|
host := r.Host
|
||||||
|
if i := strings.Index(host, ":"); i != -1 {
|
||||||
|
host = host[:i] // strip port number if present
|
||||||
|
}
|
||||||
|
r.URL.Host = host + ":" + common.ProxyHTTPSPort
|
||||||
|
logger.Info().Str("url", r.URL.String()).Msg("redirect to https")
|
||||||
http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect)
|
http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue