Skip to content

Commit 1eb691d

Browse files
committed
fix pathInfo being empty
1 parent 1935dc9 commit 1eb691d

4 files changed

Lines changed: 23 additions & 22 deletions

File tree

caddy/module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
559559
}),
560560
}
561561
rewriteHandler := rewrite.Rewrite{
562-
URI: "{http.matchers.file.relative}",
562+
URI: "{http.matchers.file.relative}{http.matchers.file.remainder}",
563563
}
564564
rewriteRoute := caddyhttp.Route{
565565
MatcherSetsRaw: []caddy.ModuleMap{rewriteMatcherSet},
@@ -573,7 +573,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
573573
// match only requests that are for PHP files
574574
var pathList []string
575575
for _, ext := range extensions {
576-
pathList = append(pathList, "*"+ext)
576+
pathList = append(pathList, "*"+ext, "*"+ext+"/*")
577577
}
578578
phpMatcherSet := caddy.ModuleMap{
579579
"path": h.JSON(pathList),

caddy/php-server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func cmdPHPServer(fs caddycmd.Flags) (int, error) {
171171
}, nil),
172172
}
173173
rewriteHandler := rewrite.Rewrite{
174-
URI: "{http.matchers.file.relative}",
174+
URI: "{http.matchers.file.relative}{http.matchers.file.remainder}",
175175
}
176176
rewriteRoute := caddyhttp.Route{
177177
MatcherSetsRaw: []caddy.ModuleMap{rewriteMatcherSet},
@@ -182,7 +182,7 @@ func cmdPHPServer(fs caddycmd.Flags) (int, error) {
182182
// match only requests that are for PHP files
183183
var pathList []string
184184
for _, ext := range extensions {
185-
pathList = append(pathList, "*"+ext)
185+
pathList = append(pathList, "*"+ext, "*"+ext+"/*")
186186
}
187187
phpMatcherSet := caddy.ModuleMap{
188188
"path": caddyconfig.JSON(pathList, nil),

cgi.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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?

context.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,7 @@ func NewRequestWithContext(r *http.Request, opts ...RequestOption) (*http.Reques
8686
}
8787
}
8888

89-
// If a worker is already assigned explicitly, use its filename and skip parsing path variables
90-
if fc.worker != nil {
91-
fc.scriptFilename = fc.worker.fileName
92-
fc.scriptName = strings.TrimPrefix(fc.worker.fileName, fc.documentRoot)
93-
} else {
94-
// If no worker was assigned, split the path into the "traditional" CGI path variables.
95-
// This needs to already happen here in case a worker script still matches the path.
96-
splitCgiPath(fc)
97-
}
89+
splitCgiPath(fc)
9890

9991
fc.requestURI = r.URL.RequestURI()
10092

0 commit comments

Comments
 (0)