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

Function NewRequestWithContext

context.go:73–105  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
73func 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
108func newDummyContext(requestPath string, opts ...RequestOption) (*frankenPHPContext, error) {

Callers 15

runTestFunction · 0.92
testPathInfoFunction · 0.92
ExampleServeHTTPFunction · 0.92
BenchmarkHelloWorldFunction · 0.92
BenchmarkEchoFunction · 0.92
BenchmarkUncommonHeadersFunction · 0.92
ExampleServeHTTP_workersFunction · 0.92
testRegisterExtensionFunction · 0.92
mainFunction · 0.92
ServeHTTPMethod · 0.92

Calls 2

newFrankenPHPContextFunction · 0.85
splitCgiPathFunction · 0.85

Tested by 11

runTestFunction · 0.74
testPathInfoFunction · 0.74
ExampleServeHTTPFunction · 0.74
BenchmarkHelloWorldFunction · 0.74
BenchmarkEchoFunction · 0.74
BenchmarkUncommonHeadersFunction · 0.74
ExampleServeHTTP_workersFunction · 0.74
assertRequestBodyFunction · 0.68