Skip to content

Commit b3d2a1d

Browse files
author
Jaybeecave
committed
Cannon
1 parent 8225c0a commit b3d2a1d

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

router.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,33 @@ func authenticate(store *datastore.Datastore, fn http.HandlerFunc, authMethod st
104104
return func(w http.ResponseWriter, req *http.Request) {
105105
// canonical host
106106
if store.Settings.CanonicalURL != "" && store.Settings.ServerIsLVE { // set in ENV
107-
root := strings.ToLower(req.URL.Host + req.URL.Path)
107+
canonical := store.Settings.CanonicalURL
108+
root := strings.ToLower(req.Host)
108109
if !strings.HasSuffix(root, "/") {
109110
root += "/"
110111
}
111-
if store.Settings.CanonicalURL != root {
112-
redirectURL := store.Settings.CanonicalURL
112+
if !strings.HasSuffix(canonical, "/") {
113+
canonical += "/"
114+
}
115+
// logrus.Info("root", root)
116+
// logrus.Info("root", canonical)
117+
if canonical != root {
118+
redirectURL := "http://"
119+
if store.Settings.IsSecured {
120+
redirectURL = "https://"
121+
}
122+
redirectURL += strings.TrimRight(canonical, "/")
123+
if req.URL.Path != "" {
124+
redirectURL += req.URL.Path
125+
// logrus.Info("0", redirectURL)
126+
}
113127
if req.URL.RawQuery != "" {
114-
logrus.Info("1", redirectURL)
115128
redirectURL += "?" + req.URL.RawQuery
129+
// logrus.Info("2", redirectURL)
116130
}
117131
if req.URL.Fragment != "" {
118-
logrus.Info("2", redirectURL)
119132
redirectURL += "#" + req.URL.Fragment
133+
// logrus.Info("2", redirectURL)
120134
}
121135

122136
logrus.Info("3", redirectURL)

0 commit comments

Comments
 (0)