Skip to content

Commit

Permalink
fix(fastcgi): SERVER_PORT variable MUST be set even it is the default…
Browse files Browse the repository at this point in the history
… port for the scheme (which omiited from a URI by client)
  • Loading branch information
ttys3 authored and francislavoie committed Feb 15, 2022
1 parent 32aad90 commit 3349d23
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,15 @@ func (t Transport) buildEnv(r *http.Request) (envVars, error) {
}

// compliance with the CGI specification requires that
// SERVER_PORT should only exist if it's a valid numeric value.
// Info: https://www.ietf.org/rfc/rfc3875 Page 18
// the SERVER_PORT variable MUST be set to the TCP/IP port number on which this request is received from the client
// even if the port is the default port for the scheme and could otherwise be omitted from a URI.
// https://tools.ietf.org/html/rfc3875#section-4.1.15
if reqPort != "" {
env["SERVER_PORT"] = reqPort
} else if requestScheme == "http" {
env["SERVER_PORT"] = "80"
} else if requestScheme == "https" {
env["SERVER_PORT"] = "443"
}

// Some web apps rely on knowing HTTPS or not
Expand Down

0 comments on commit 3349d23

Please sign in to comment.