Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions proxy/fastcgi/fastcgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,27 @@ func NewRoundTripper(log logging.Logger, addr, filename string) (*RoundTripper,
return nil, fmt.Errorf("gofast: failed creating client: %w", err)
}

handler := gofast.NewFileEndpoint(filename)(gofast.BasicSession)
chain := gofast.Chain(
gofast.BasicParamsMap,
gofast.MapHeader,
gofast.MapEndpoint(filename),
func(handler gofast.SessionHandler) gofast.SessionHandler {
return func(client gofast.Client, req *gofast.Request) (*gofast.ResponsePipe, error) {
req.Params["HTTP_HOST"] = req.Params["SERVER_NAME"]
req.Params["SERVER_SOFTWARE"] = "Skipper"

// Gofast sets this param to `fastcgi` which is not what the backend will expect.
delete(req.Params, "REQUEST_SCHEME")

return handler(client, req)
}
},
)

return &RoundTripper{
log: log,
client: client,
handler: handler,
handler: chain(gofast.BasicSession),
}, nil
}

Expand Down
9 changes: 9 additions & 0 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,15 @@ func (p *Proxy) makeBackendRequest(ctx *context) (*http.Response, *proxyError) {
return nil, &proxyError{err: err}
}

// FastCgi expects the Host to be in form host:port
// It will then be split and added as 2 separate params to the backend process
if _, _, err := net.SplitHostPort(req.Host); err != nil {
req.Host = req.Host + ":" + req.URL.Port()
}

// RemoteAddr is needed to pass to the backend process as param
req.RemoteAddr = ctx.request.RemoteAddr

response, err = rt.RoundTrip(req)
if err != nil {
p.log.Errorf("Failed to roundtrip to fastcgi: %v", err)
Expand Down