Browse Source

fixing host matching in caddy integration

Stephen Searles 1 year ago
parent
commit
1196033364
2 changed files with 7 additions and 5 deletions
  1. 6
    4
      http.go
  2. 1
    1
      testdir/caddyfile

+ 6
- 4
http.go View File

@@ -109,9 +109,10 @@ func (ch *CaddyHugo) ServeNewContent(w http.ResponseWriter, r *http.Request) (in
109 109
 
110 110
 func (ch *CaddyHugo) Middleware(c *caddy.Controller) httpserver.Middleware {
111 111
 	return func(next httpserver.Handler) httpserver.Handler {
112
-		host := net.JoinHostPort(ch.Site.Addr.Host, ch.Site.Addr.Port)
112
+		host := ch.Site.Addr.Host
113
+		hostport := net.JoinHostPort(ch.Site.Addr.Host, ch.Site.Addr.Port)
113 114
 		return httpserver.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
114
-			if r.Host != host {
115
+			if r.Host != host && r.Host != hostport {
115 116
 				return next.ServeHTTP(w, r)
116 117
 			}
117 118
 			return ch.ServeHTTPWithNext(next, w, r)
@@ -125,8 +126,9 @@ func (ch *CaddyHugo) Auth(r *http.Request) bool {
125 126
 }
126 127
 
127 128
 func (ch *CaddyHugo) Match(r *http.Request) bool {
128
-	host := net.JoinHostPort(ch.Site.Addr.Host, ch.Site.Addr.Port)
129
-	if r.Host != host {
129
+	host := ch.Site.Addr.Host
130
+	hostport := net.JoinHostPort(ch.Site.Addr.Host, ch.Site.Addr.Port)
131
+	if r.Host != host && r.Host != hostport {
130 132
 		return false
131 133
 	}
132 134
 	if strings.HasPrefix(r.URL.Path, "/media/") {

+ 1
- 1
testdir/caddyfile View File

@@ -7,7 +7,7 @@ localhost:8080 {
7 7
 	pprof
8 8
 }
9 9
 
10
-localhost:8081 {
10
+localhost:8081, localhost:8082 {
11 11
 	root ./testsite2
12 12
 	hugo
13 13
 	errors { * }

Loading…
Cancel
Save