@marcel91200 / caddy Mirror · read-only / commits / 5c8b5029
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

fastcgi: Set SERVER_SOFTWARE, _NAME, and _PORT properly (fixes #2952)

Matthew Holt committed Dec 28, 2019 at 16:35 UTC 5c8b502964457646ada348c6bc8ba7180771b7ca
1 file changed +16 -9
modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go
+16 -9
@@ -18,6 +18,7 @@ import (
18 "context"
19 "crypto/tls"
20 "fmt"
21 + "net"
22 "net/http"
23 "path"
24 "path/filepath"
@@ -38,12 +39,6 @@ func init() {
39
40 // Transport facilitates FastCGI communication.
41 type Transport struct {
41 - // TODO: Populate these
42 - softwareName string
43 - softwareVersion string
44 - serverName string
45 - serverPort string
46 -
42 // Use this directory as the fastcgi root directory. Defaults to the root
43 // directory of the parent virtual host.
44 Root string `json:"root,omitempty"`
@@ -68,6 +63,8 @@ type Transport struct {
63
64 // The duration used to set a deadline when sending to the FastCGI server.
65 WriteTimeout caddy.Duration `json:"write_timeout,omitempty"`
66 +
67 + serverSoftware string
68 }
69
70 // CaddyModule returns the Caddy module information.
@@ -83,6 +80,10 @@ func (t *Transport) Provision(_ caddy.Context) error {
80 if t.Root == "" {
81 t.Root = "{http.vars.root}"
82 }
83 + t.serverSoftware = "Caddy"
84 + if mod := caddy.GoModule(); mod.Version != "" {
85 + t.serverSoftware += "/" + mod.Version
86 + }
87 return nil
88 }
89
@@ -206,6 +207,12 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
207 requestScheme = "https"
208 }
209
210 + reqHost, reqPort, err := net.SplitHostPort(r.Host)
211 + if err != nil {
212 + // whatever, just assume there was no port
213 + reqHost = r.Host
214 + }
215 +
216 // Some variables are unused but cleared explicitly to prevent
217 // the parent environment from interfering.
218 env = map[string]string{
@@ -223,10 +230,10 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
230 "REMOTE_USER": "", // TODO: once there are authentication handlers, populate this
231 "REQUEST_METHOD": r.Method,
232 "REQUEST_SCHEME": requestScheme,
226 - "SERVER_NAME": t.serverName,
227 - "SERVER_PORT": t.serverPort,
233 + "SERVER_NAME": reqHost,
234 + "SERVER_PORT": reqPort,
235 "SERVER_PROTOCOL": r.Proto,
229 - "SERVER_SOFTWARE": t.softwareName + "/" + t.softwareVersion,
236 + "SERVER_SOFTWARE": t.serverSoftware,
237
238 // Other variables
239 "DOCUMENT_ROOT": root,