mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-06 22:40:31 -05:00
fastcgi: Set SERVER_SOFTWARE, _NAME, and _PORT properly (fixes #2952)
This commit is contained in:
parent
82bebfab8a
commit
5c8b502964
1 changed files with 16 additions and 9 deletions
|
@ -18,6 +18,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -38,12 +39,6 @@ func init() {
|
||||||
|
|
||||||
// Transport facilitates FastCGI communication.
|
// Transport facilitates FastCGI communication.
|
||||||
type Transport struct {
|
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
|
// Use this directory as the fastcgi root directory. Defaults to the root
|
||||||
// directory of the parent virtual host.
|
// directory of the parent virtual host.
|
||||||
Root string `json:"root,omitempty"`
|
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.
|
// The duration used to set a deadline when sending to the FastCGI server.
|
||||||
WriteTimeout caddy.Duration `json:"write_timeout,omitempty"`
|
WriteTimeout caddy.Duration `json:"write_timeout,omitempty"`
|
||||||
|
|
||||||
|
serverSoftware string
|
||||||
}
|
}
|
||||||
|
|
||||||
// CaddyModule returns the Caddy module information.
|
// CaddyModule returns the Caddy module information.
|
||||||
|
@ -83,6 +80,10 @@ func (t *Transport) Provision(_ caddy.Context) error {
|
||||||
if t.Root == "" {
|
if t.Root == "" {
|
||||||
t.Root = "{http.vars.root}"
|
t.Root = "{http.vars.root}"
|
||||||
}
|
}
|
||||||
|
t.serverSoftware = "Caddy"
|
||||||
|
if mod := caddy.GoModule(); mod.Version != "" {
|
||||||
|
t.serverSoftware += "/" + mod.Version
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +207,12 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
|
||||||
requestScheme = "https"
|
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
|
// Some variables are unused but cleared explicitly to prevent
|
||||||
// the parent environment from interfering.
|
// the parent environment from interfering.
|
||||||
env = map[string]string{
|
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
|
"REMOTE_USER": "", // TODO: once there are authentication handlers, populate this
|
||||||
"REQUEST_METHOD": r.Method,
|
"REQUEST_METHOD": r.Method,
|
||||||
"REQUEST_SCHEME": requestScheme,
|
"REQUEST_SCHEME": requestScheme,
|
||||||
"SERVER_NAME": t.serverName,
|
"SERVER_NAME": reqHost,
|
||||||
"SERVER_PORT": t.serverPort,
|
"SERVER_PORT": reqPort,
|
||||||
"SERVER_PROTOCOL": r.Proto,
|
"SERVER_PROTOCOL": r.Proto,
|
||||||
"SERVER_SOFTWARE": t.softwareName + "/" + t.softwareVersion,
|
"SERVER_SOFTWARE": t.serverSoftware,
|
||||||
|
|
||||||
// Other variables
|
// Other variables
|
||||||
"DOCUMENT_ROOT": root,
|
"DOCUMENT_ROOT": root,
|
||||||
|
|
Loading…
Reference in a new issue