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

Function splitCgiPath

cgi.go:198–233  ·  view source on GitHub ↗

splitCgiPath splits the request path into SCRIPT_NAME, SCRIPT_FILENAME, PATH_INFO, DOCUMENT_URI

(fc *frankenPHPContext)

Source from the content-addressed store, hash-verified

196
197// splitCgiPath splits the request path into SCRIPT_NAME, SCRIPT_FILENAME, PATH_INFO, DOCUMENT_URI
198func splitCgiPath(fc *frankenPHPContext) {
199 path := fc.request.URL.Path
200 splitPath := fc.splitPath
201
202 if splitPath == nil {
203 splitPath = []string{".php"}
204 }
205
206 if splitPos := splitPos(path, splitPath); splitPos > -1 {
207 fc.docURI = path[:splitPos]
208 fc.pathInfo = path[splitPos:]
209 }
210
211 // If a worker is already assigned explicitly, derive SCRIPT_NAME from its filename
212 if fc.worker != nil {
213 fc.scriptFilename = fc.worker.fileName
214 docRootWithSep := fc.documentRoot + string(filepath.Separator)
215 if strings.HasPrefix(fc.worker.fileName, docRootWithSep) {
216 fc.scriptName = filepath.ToSlash(strings.TrimPrefix(fc.worker.fileName, fc.documentRoot))
217 } else {
218 fc.docURI = ""
219 fc.pathInfo = ""
220 }
221 return
222 }
223
224 // Strip PATH_INFO from SCRIPT_NAME
225 // Ensure the SCRIPT_NAME has a leading slash for compliance with RFC3875
226 // Info: https://tools.ietf.org/html/rfc3875#section-4.1.13
227 fc.scriptName = ensureLeadingSlash(strings.TrimSuffix(path, fc.pathInfo))
228
229 // TODO: is it possible to delay this and avoid saving everything in the context?
230 // SCRIPT_FILENAME is the absolute path of SCRIPT_NAME
231 fc.scriptFilename = sanitizedPathJoin(fc.documentRoot, fc.scriptName)
232 fc.worker = workersByPath[fc.scriptFilename]
233}
234
235// splitPos returns the index where path should be split based on splitPath.
236// example: if splitPath is [".php"]

Callers 1

NewRequestWithContextFunction · 0.85

Calls 3

splitPosFunction · 0.85
ensureLeadingSlashFunction · 0.85
sanitizedPathJoinFunction · 0.85

Tested by

no test coverage detected