diff options
Diffstat (limited to 'modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go')
-rw-r--r-- | modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go b/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go index 9d2dc39..cff6b39 100644 --- a/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go +++ b/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go @@ -29,6 +29,7 @@ import ( "github.com/caddyserver/caddy/v2/modules/caddyhttp" "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy" "github.com/caddyserver/caddy/v2/modules/caddytls" + "go.uber.org/zap" "github.com/caddyserver/caddy/v2" ) @@ -66,6 +67,7 @@ type Transport struct { WriteTimeout caddy.Duration `json:"write_timeout,omitempty"` serverSoftware string + logger *zap.Logger } // CaddyModule returns the Caddy module information. @@ -77,7 +79,8 @@ func (Transport) CaddyModule() caddy.ModuleInfo { } // Provision sets up t. -func (t *Transport) Provision(_ caddy.Context) error { +func (t *Transport) Provision(ctx caddy.Context) error { + t.logger = ctx.Logger(t) if t.Root == "" { t.Root = "{http.vars.root}" } @@ -110,6 +113,12 @@ func (t Transport) RoundTrip(r *http.Request) (*http.Response, error) { address = dialInfo.Address } + t.logger.Debug("roundtrip", + zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: r}), + zap.String("dial", address), + zap.Any("env", env), // TODO: this uses reflection I think + ) + fcgiBackend, err := DialContext(ctx, network, address) if err != nil { // TODO: wrap in a special error type if the dial failed, so retries can happen if enabled @@ -164,7 +173,12 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) { ip = strings.Replace(ip, "[", "", 1) ip = strings.Replace(ip, "]", "", 1) - root := repl.ReplaceAll(t.Root, ".") + // make sure file root is absolute + root, err := filepath.Abs(repl.ReplaceAll(t.Root, ".")) + if err != nil { + return nil, err + } + fpath := r.URL.Path // Split path in preparation for env variables. @@ -173,8 +187,8 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) { splitPos := t.splitPos(fpath) // Request has the extension; path was split successfully - docURI := fpath[:splitPos+len(t.SplitPath)] - pathInfo := fpath[splitPos+len(t.SplitPath):] + docURI := fpath[:splitPos] + pathInfo := fpath[splitPos:] scriptName := fpath // Strip PATH_INFO from SCRIPT_NAME @@ -292,7 +306,7 @@ func (t Transport) splitPos(path string) int { lowerPath := strings.ToLower(path) for _, split := range t.SplitPath { if idx := strings.Index(lowerPath, strings.ToLower(split)); idx > -1 { - return idx + return idx + len(split) } } return -1 |