From 11960333646847894232d554ea9c1add70aa2a29 Mon Sep 17 00:00:00 2001 From: Stephen Searles Date: Thu, 7 Sep 2017 16:59:34 -0500 Subject: [PATCH] fixing host matching in caddy integration --- http.go | 10 ++++++---- testdir/caddyfile | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/http.go b/http.go index 707f4a8..96d83aa 100644 --- a/http.go +++ b/http.go @@ -109,9 +109,10 @@ func (ch *CaddyHugo) ServeNewContent(w http.ResponseWriter, r *http.Request) (in func (ch *CaddyHugo) Middleware(c *caddy.Controller) httpserver.Middleware { return func(next httpserver.Handler) httpserver.Handler { - host := net.JoinHostPort(ch.Site.Addr.Host, ch.Site.Addr.Port) + host := ch.Site.Addr.Host + hostport := net.JoinHostPort(ch.Site.Addr.Host, ch.Site.Addr.Port) return httpserver.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) { - if r.Host != host { + if r.Host != host && r.Host != hostport { return next.ServeHTTP(w, r) } return ch.ServeHTTPWithNext(next, w, r) @@ -125,8 +126,9 @@ func (ch *CaddyHugo) Auth(r *http.Request) bool { } func (ch *CaddyHugo) Match(r *http.Request) bool { - host := net.JoinHostPort(ch.Site.Addr.Host, ch.Site.Addr.Port) - if r.Host != host { + host := ch.Site.Addr.Host + hostport := net.JoinHostPort(ch.Site.Addr.Host, ch.Site.Addr.Port) + if r.Host != host && r.Host != hostport { return false } if strings.HasPrefix(r.URL.Path, "/media/") { diff --git a/testdir/caddyfile b/testdir/caddyfile index 1800280..823885a 100644 --- a/testdir/caddyfile +++ b/testdir/caddyfile @@ -7,7 +7,7 @@ localhost:8080 { pprof } -localhost:8081 { +localhost:8081, localhost:8082 { root ./testsite2 hugo errors { * }