@@ -111,6 +111,8 @@ func addKnownVariablesToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
111111 requestURI = fc .requestURI
112112 }
113113
114+ phpSelf := fc .scriptName + fc .pathInfo
115+
114116 C .frankenphp_register_server_vars (trackVarsArray , C.frankenphp_server_vars {
115117 // approximate total length to avoid array re-hashing:
116118 // 28 CGI vars + headers + environment
@@ -127,8 +129,8 @@ func addKnownVariablesToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
127129 document_root_len : C .size_t (len (fc .documentRoot )),
128130 path_info : toUnsafeChar (fc .pathInfo ),
129131 path_info_len : C .size_t (len (fc .pathInfo )),
130- php_self : toUnsafeChar (fc . scriptName ),
131- php_self_len : C .size_t (len (fc . scriptName )),
132+ php_self : toUnsafeChar (phpSelf ),
133+ php_self_len : C .size_t (len (phpSelf )),
132134 document_uri : toUnsafeChar (fc .docURI ),
133135 document_uri_len : C .size_t (len (fc .docURI )),
134136 script_filename : toUnsafeChar (fc .scriptFilename ),
@@ -206,15 +208,22 @@ func splitCgiPath(fc *frankenPHPContext) {
206208 if splitPos := splitPos (path , splitPath ); splitPos > - 1 {
207209 fc .docURI = path [:splitPos ]
208210 fc .pathInfo = path [splitPos :]
211+ }
209212
210- // Strip PATH_INFO from SCRIPT_NAME
211- fc .scriptName = strings .TrimSuffix (path , fc .pathInfo )
213+ // If a worker is already assigned explicitly, derive SCRIPT_NAME from its filename
214+ if fc .worker != nil {
215+ fc .scriptFilename = fc .worker .fileName
216+ fc .scriptName = strings .TrimPrefix (fc .worker .fileName , fc .documentRoot )
217+ return
218+ }
212219
213- // Ensure the SCRIPT_NAME has a leading slash for compliance with RFC3875
214- // Info: https://tools.ietf.org/html/rfc3875#section-4.1.13
215- if fc .scriptName != "" && ! strings .HasPrefix (fc .scriptName , "/" ) {
216- fc .scriptName = "/" + fc .scriptName
217- }
220+ // Strip PATH_INFO from SCRIPT_NAME
221+ fc .scriptName = strings .TrimSuffix (path , fc .pathInfo )
222+
223+ // Ensure the SCRIPT_NAME has a leading slash for compliance with RFC3875
224+ // Info: https://tools.ietf.org/html/rfc3875#section-4.1.13
225+ if fc .scriptName != "" && ! strings .HasPrefix (fc .scriptName , "/" ) {
226+ fc .scriptName = "/" + fc .scriptName
218227 }
219228
220229 // TODO: is it possible to delay this and avoid saving everything in the context?
0 commit comments