Skip to content

Commit 708b233

Browse files
committed
fix $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF'] in php_server workers
apache passes PHP_SELF as SCRIPT_NAME + REQUEST_URL, but the docs say it's the same as SCRIPT_NAME and that's how Caddy+fpm behave too
1 parent 006f37f commit 708b233

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/caddy/frankenphp/Build
2+
/caddy/frankenphp/Caddyfile.test
23
/caddy/frankenphp/frankenphp
34
/caddy/frankenphp/frankenphp.exe
5+
/caddy/frankenphp/public
46
/dist
57
/github_conf
68
/internal/testserver/testserver

cgi.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ func addKnownVariablesToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
111111
requestURI = fc.requestURI
112112
}
113113

114-
requestPath := ensureLeadingSlash(request.URL.Path)
115-
116114
C.frankenphp_register_server_vars(trackVarsArray, C.frankenphp_server_vars{
117115
// approximate total length to avoid array re-hashing:
118116
// 28 CGI vars + headers + environment
@@ -129,8 +127,8 @@ func addKnownVariablesToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
129127
document_root_len: C.size_t(len(fc.documentRoot)),
130128
path_info: toUnsafeChar(fc.pathInfo),
131129
path_info_len: C.size_t(len(fc.pathInfo)),
132-
php_self: toUnsafeChar(requestPath),
133-
php_self_len: C.size_t(len(requestPath)),
130+
php_self: toUnsafeChar(fc.scriptName),
131+
php_self_len: C.size_t(len(fc.scriptName)),
134132
document_uri: toUnsafeChar(fc.docURI),
135133
document_uri_len: C.size_t(len(fc.docURI)),
136134
script_filename: toUnsafeChar(fc.scriptFilename),

context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func NewRequestWithContext(r *http.Request, opts ...RequestOption) (*http.Reques
8989
// If a worker is already assigned explicitly, use its filename and skip parsing path variables
9090
if fc.worker != nil {
9191
fc.scriptFilename = fc.worker.fileName
92+
fc.scriptName = strings.TrimPrefix(fc.worker.fileName, fc.documentRoot)
9293
} else {
9394
// If no worker was assigned, split the path into the "traditional" CGI path variables.
9495
// This needs to already happen here in case a worker script still matches the path.

0 commit comments

Comments
 (0)