NewRequestWithContext creates a new FrankenPHP request context. FrankenPHP does not strip request headers whose name contains an underscore. Because CGI maps dashes to underscores ("Foo-Bar" becomes the HTTP_FOO_BAR variable), a client-supplied "Foo_Bar" header is indistinguishable from the legitim
(r *http.Request, opts ...RequestOption)
| 71 | // you explicitly need (and whitelist) them. The Caddy-based server and reverse |
| 72 | // proxies such as nginx (underscores_in_headers off) already do this. |
| 73 | func NewRequestWithContext(r *http.Request, opts ...RequestOption) (*http.Request, error) { |
| 74 | fc := newFrankenPHPContext() |
| 75 | fc.request = r |
| 76 | |
| 77 | for _, o := range opts { |
| 78 | if err := o(fc); err != nil { |
| 79 | return nil, err |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if fc.logger == nil { |
| 84 | fc.logger = globalLogger |
| 85 | } |
| 86 | |
| 87 | if fc.documentRoot == "" { |
| 88 | if EmbeddedAppPath != "" { |
| 89 | fc.documentRoot = EmbeddedAppPath |
| 90 | } else { |
| 91 | var err error |
| 92 | if fc.documentRoot, err = os.Getwd(); err != nil { |
| 93 | return nil, err |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | splitCgiPath(fc) |
| 99 | |
| 100 | fc.requestURI = r.URL.RequestURI() |
| 101 | |
| 102 | c := context.WithValue(r.Context(), contextKey, fc) |
| 103 | |
| 104 | return r.WithContext(c), nil |
| 105 | } |
| 106 | |
| 107 | // newDummyContext creates a fake context from a request path |
| 108 | func newDummyContext(requestPath string, opts ...RequestOption) (*frankenPHPContext, error) { |