mirror of
https://github.com/caddyserver/caddy.git
synced 2026-06-07 14:35:23 -04:00
Merge pull request #2737 from caddyserver/fastcgi (reverse proxy!)
v2: Refactor reverse proxy and add FastCGI support
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -58,6 +59,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), caddy.ReplacerCtxKey, repl)
|
||||
ctx = context.WithValue(ctx, ServerCtxKey, s)
|
||||
ctx = context.WithValue(ctx, VarCtxKey, make(map[string]interface{}))
|
||||
ctx = context.WithValue(ctx, OriginalURLCtxKey, cloneURL(r.URL))
|
||||
r = r.WithContext(ctx)
|
||||
|
||||
// once the pointer to the request won't change
|
||||
@@ -168,7 +170,7 @@ func (s *Server) enforcementHandler(w http.ResponseWriter, r *http.Request, next
|
||||
// listeners in s that use a port which is not otherPort.
|
||||
func (s *Server) listenersUseAnyPortOtherThan(otherPort int) bool {
|
||||
for _, lnAddr := range s.Listen {
|
||||
_, addrs, err := caddy.ParseListenAddr(lnAddr)
|
||||
_, addrs, err := caddy.ParseNetworkAddress(lnAddr)
|
||||
if err == nil {
|
||||
for _, a := range addrs {
|
||||
_, port, err := net.SplitHostPort(a)
|
||||
@@ -254,6 +256,18 @@ type HTTPErrorConfig struct {
|
||||
Routes RouteList `json:"routes,omitempty"`
|
||||
}
|
||||
|
||||
// cloneURL makes a copy of r.URL and returns a
|
||||
// new value that doesn't reference the original.
|
||||
func cloneURL(u *url.URL) url.URL {
|
||||
urlCopy := *u
|
||||
if u.User != nil {
|
||||
userInfo := new(url.Userinfo)
|
||||
*userInfo = *u.User
|
||||
urlCopy.User = userInfo
|
||||
}
|
||||
return urlCopy
|
||||
}
|
||||
|
||||
// Context keys for HTTP request context values.
|
||||
const (
|
||||
// For referencing the server instance
|
||||
@@ -261,4 +275,7 @@ const (
|
||||
|
||||
// For the request's variable table
|
||||
VarCtxKey caddy.CtxKey = "vars"
|
||||
|
||||
// For the unmodified URL that originally came in with a request
|
||||
OriginalURLCtxKey caddy.CtxKey = "original_url"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user