-
Notifications
You must be signed in to change notification settings - Fork 444
fix: set $_SERVER variables: 'SCRIPT_NAME', 'PHP_SELF', and 'PATH_INFO' #2317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 17 commits
708b233
1935dc9
1eb691d
3708b41
2a32861
652322b
fd6595e
b8a981d
91a6968
0a294ac
b632a5e
c5481d0
6fc5c15
7375dce
2dc7270
44519f5
5f9c77f
786b6be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,7 @@ func addKnownVariablesToServer(fc *frankenPHPContext, trackVarsArray *C.zval) { | |
| requestURI = fc.requestURI | ||
| } | ||
|
|
||
| requestPath := ensureLeadingSlash(request.URL.Path) | ||
| phpSelf := fc.scriptName + fc.pathInfo | ||
|
|
||
| C.frankenphp_register_server_vars(trackVarsArray, C.frankenphp_server_vars{ | ||
| // approximate total length to avoid array re-hashing: | ||
|
|
@@ -129,8 +129,8 @@ func addKnownVariablesToServer(fc *frankenPHPContext, trackVarsArray *C.zval) { | |
| document_root_len: C.size_t(len(fc.documentRoot)), | ||
| path_info: toUnsafeChar(fc.pathInfo), | ||
| path_info_len: C.size_t(len(fc.pathInfo)), | ||
| php_self: toUnsafeChar(requestPath), | ||
| php_self_len: C.size_t(len(requestPath)), | ||
| php_self: toUnsafeChar(phpSelf), | ||
| php_self_len: C.size_t(len(phpSelf)), | ||
| document_uri: toUnsafeChar(fc.docURI), | ||
| document_uri_len: C.size_t(len(fc.docURI)), | ||
| script_filename: toUnsafeChar(fc.scriptFilename), | ||
|
|
@@ -208,17 +208,25 @@ func splitCgiPath(fc *frankenPHPContext) { | |
| if splitPos := splitPos(path, splitPath); splitPos > -1 { | ||
| fc.docURI = path[:splitPos] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just realized the same is true for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't even know that's a server variable. Will move the check up later. |
||
| fc.pathInfo = path[splitPos:] | ||
AlliBalliBaba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Strip PATH_INFO from SCRIPT_NAME | ||
| fc.scriptName = strings.TrimSuffix(path, fc.pathInfo) | ||
|
|
||
| // Ensure the SCRIPT_NAME has a leading slash for compliance with RFC3875 | ||
| // Info: https://tools.ietf.org/html/rfc3875#section-4.1.13 | ||
| if fc.scriptName != "" && !strings.HasPrefix(fc.scriptName, "/") { | ||
| fc.scriptName = "/" + fc.scriptName | ||
| // If a worker is already assigned explicitly, derive SCRIPT_NAME from its filename | ||
| if fc.worker != nil { | ||
| fc.scriptFilename = fc.worker.fileName | ||
| docRootWithSep := fc.documentRoot + string(filepath.Separator) | ||
| if strings.HasPrefix(fc.worker.fileName, docRootWithSep) { | ||
| fc.scriptName = filepath.ToSlash(strings.TrimPrefix(fc.worker.fileName, fc.documentRoot)) | ||
| } else { | ||
| fc.pathInfo = "" | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // Strip PATH_INFO from SCRIPT_NAME | ||
| // Ensure the SCRIPT_NAME has a leading slash for compliance with RFC3875 | ||
| // Info: https://tools.ietf.org/html/rfc3875#section-4.1.13 | ||
| fc.scriptName = ensureLeadingSlash(strings.TrimSuffix(path, fc.pathInfo)) | ||
|
|
||
| // TODO: is it possible to delay this and avoid saving everything in the context? | ||
| // SCRIPT_FILENAME is the absolute path of SCRIPT_NAME | ||
| fc.scriptFilename = sanitizedPathJoin(fc.documentRoot, fc.scriptName) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
|
|
||
| ignore_user_abort(true); | ||
|
|
||
| $handler = static function() { | ||
| echo "SCRIPT_NAME: " . ($_SERVER['SCRIPT_NAME'] ?? '(not set)') . "<br>"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: you could add |
||
| echo "SCRIPT_FILENAME: " . ($_SERVER['SCRIPT_FILENAME'] ?? '(not set)') . "<br>"; | ||
| echo "PHP_SELF: " . ($_SERVER['PHP_SELF'] ?? '(not set)') . "<br>"; | ||
| echo "PATH_INFO: " . ($_SERVER['PATH_INFO'] ?? '(not set)') . "<br>"; | ||
| echo "DOCUMENT_ROOT: " . ($_SERVER['DOCUMENT_ROOT'] ?? '(not set)') . "<br>"; | ||
| echo "REQUEST_URI: " . ($_SERVER['REQUEST_URI'] ?? '(not set)') . "<br>"; | ||
| }; | ||
|
|
||
| if (isset($_SERVER['FRANKENPHP_WORKER'])) { | ||
| for ($nbRequests = 0, $running = true; $running; ++$nbRequests) { | ||
| $running = \frankenphp_handle_request($handler); | ||
| gc_collect_cycles(); | ||
| } | ||
| } else { | ||
| $handler(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added these because I often times find myself verifying bug reports there
I'm thinking they're fine in the .gitignore, but if you want I can revert