summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-12-28 16:35:29 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2019-12-28 16:35:29 -0700
commit5c8b502964457646ada348c6bc8ba7180771b7ca (patch)
treebe5a2793c4b31acfad6d21b54181ff49e7183946 /modules
parent82bebfab8a6528f24f23dac99ce5b11efab27761 (diff)
fastcgi: Set SERVER_SOFTWARE, _NAME, and _PORT properly (fixes #2952)
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go b/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go
index f3f979d..c0dda29 100644
--- a/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go
+++ b/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go
@@ -18,6 +18,7 @@ import (
"context"
"crypto/tls"
"fmt"
+ "net"
"net/http"
"path"
"path/filepath"
@@ -38,12 +39,6 @@ func init() {
// Transport facilitates FastCGI communication.
type Transport struct {
- // TODO: Populate these
- softwareName string
- softwareVersion string
- serverName string
- serverPort string
-
// Use this directory as the fastcgi root directory. Defaults to the root
// directory of the parent virtual host.
Root string `json:"root,omitempty"`
@@ -68,6 +63,8 @@ type Transport struct {
// The duration used to set a deadline when sending to the FastCGI server.
WriteTimeout caddy.Duration `json:"write_timeout,omitempty"`
+
+ serverSoftware string
}
// CaddyModule returns the Caddy module information.
@@ -83,6 +80,10 @@ func (t *Transport) Provision(_ caddy.Context) error {
if t.Root == "" {
t.Root = "{http.vars.root}"
}
+ t.serverSoftware = "Caddy"
+ if mod := caddy.GoModule(); mod.Version != "" {
+ t.serverSoftware += "/" + mod.Version
+ }
return nil
}
@@ -206,6 +207,12 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
requestScheme = "https"
}
+ reqHost, reqPort, err := net.SplitHostPort(r.Host)
+ if err != nil {
+ // whatever, just assume there was no port
+ reqHost = r.Host
+ }
+
// Some variables are unused but cleared explicitly to prevent
// the parent environment from interfering.
env = map[string]string{
@@ -223,10 +230,10 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
"REMOTE_USER": "", // TODO: once there are authentication handlers, populate this
"REQUEST_METHOD": r.Method,
"REQUEST_SCHEME": requestScheme,
- "SERVER_NAME": t.serverName,
- "SERVER_PORT": t.serverPort,
+ "SERVER_NAME": reqHost,
+ "SERVER_PORT": reqPort,
"SERVER_PROTOCOL": r.Proto,
- "SERVER_SOFTWARE": t.softwareName + "/" + t.softwareVersion,
+ "SERVER_SOFTWARE": t.serverSoftware,
// Other variables
"DOCUMENT_ROOT": root,