MCPcopy Index your code
hub / github.com/php/frankenphp / addKnownVariablesToServer

Function addKnownVariablesToServer

cgi.go:45–158  ·  view source on GitHub ↗

computeKnownVariables returns a set of CGI environment variables for the request. TODO: handle this case https://github.com/caddyserver/caddy/issues/3718 Inspired by https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go

(fc *frankenPHPContext, trackVarsArray *C.zval)

Source from the content-addressed store, hash-verified

43// TODO: handle this case https://github.com/caddyserver/caddy/issues/3718
44// Inspired by https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go
45func addKnownVariablesToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
46 request := fc.request
47 // Separate remote IP and port; more lenient than net.SplitHostPort
48 var ip, port string
49 if idx := strings.LastIndex(request.RemoteAddr, ":"); idx > -1 {
50 ip = request.RemoteAddr[:idx]
51 port = request.RemoteAddr[idx+1:]
52 } else {
53 ip = request.RemoteAddr
54 }
55
56 // Remove [] from IPv6 addresses
57 if len(ip) > 0 && ip[0] == '[' {
58 ip = ip[1 : len(ip)-1]
59 }
60
61 var rs, https, sslProtocol *C.zend_string
62 var sslCipher string
63
64 if request.TLS == nil {
65 rs = C.frankenphp_strings.httpLowercase
66 https = C.frankenphp_strings.empty
67 sslProtocol = C.frankenphp_strings.empty
68 sslCipher = ""
69 } else {
70 rs = C.frankenphp_strings.httpsLowercase
71 https = C.frankenphp_strings.on
72
73 // and pass the protocol details in a manner compatible with Apache's mod_ssl
74 // (which is why these have an SSL_ prefix and not TLS_).
75 sslProtocol = tlsProtocol(request.TLS.Version)
76
77 if request.TLS.CipherSuite != 0 {
78 sslCipher = tls.CipherSuiteName(request.TLS.CipherSuite)
79 }
80 }
81
82 reqHost, reqPort, _ := net.SplitHostPort(request.Host)
83
84 if reqHost == "" {
85 // whatever, just assume there was no port
86 reqHost = request.Host
87 }
88
89 if reqPort == "" {
90 // compliance with the CGI specification requires that
91 // the SERVER_PORT variable MUST be set to the TCP/IP port number on which this request is received from the client
92 // even if the port is the default port for the scheme and could otherwise be omitted from a URI.
93 // https://tools.ietf.org/html/rfc3875#section-4.1.15
94 switch rs {
95 case C.frankenphp_strings.httpsLowercase:
96 reqPort = "443"
97 case C.frankenphp_strings.httpLowercase:
98 reqPort = "80"
99 }
100 }
101
102 serverPort := reqPort

Callers 1

Calls 3

tlsProtocolFunction · 0.85
toUnsafeCharFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected