mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-03 06:37:14 +01:00
Proxy destination may include scheme
This commit is contained in:
parent
f2f5d4984d
commit
9f793dad28
1 changed files with 15 additions and 5 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
)
|
)
|
||||||
|
@ -29,14 +30,23 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
|
||||||
|
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
if middleware.Path(r.URL.Path).Matches(rule.from) {
|
if middleware.Path(r.URL.Path).Matches(rule.from) {
|
||||||
var scheme string
|
var base string
|
||||||
if r.TLS == nil {
|
|
||||||
scheme = "http"
|
if strings.HasPrefix(rule.to, "http") { // includes https
|
||||||
|
// destination includes a scheme! no need to guess
|
||||||
|
base = rule.to
|
||||||
} else {
|
} else {
|
||||||
scheme = "https"
|
// no scheme specified; assume same as request
|
||||||
|
var scheme string
|
||||||
|
if r.TLS == nil {
|
||||||
|
scheme = "http"
|
||||||
|
} else {
|
||||||
|
scheme = "https"
|
||||||
|
}
|
||||||
|
base = scheme + "://" + rule.to
|
||||||
}
|
}
|
||||||
|
|
||||||
baseUrl, err := url.Parse(scheme + "://" + rule.to)
|
baseUrl, err := url.Parse(base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue