@@ -40,6 +40,7 @@ func fromContext(ctx context.Context) (fctx *frankenPHPContext, ok bool) {
4040 return
4141}
4242
43+ // NewFrankenPHPContext parses out the correct filename and context to pass to NewRequestWithExistingContext
4344func NewFrankenPHPContext (r * http.Request , opts ... RequestOption ) (string , * frankenPHPContext , error ) {
4445 fc := & frankenPHPContext {
4546 done : make (chan interface {}),
@@ -94,22 +95,21 @@ func NewFrankenPHPContext(r *http.Request, opts ...RequestOption) (string, *fran
9495 return fc .scriptFilename , fc , nil
9596}
9697
98+ // NewRequestWithExistingContext wraps an http request with an existing FrankenPHP request context.
99+ func NewRequestWithExistingContext (r * http.Request , fc * frankenPHPContext ) * http.Request {
100+ c := context .WithValue (r .Context (), contextKey , fc )
101+
102+ return r .WithContext (c )
103+ }
104+
97105// NewRequestWithContext creates a new FrankenPHP request context.
98106func NewRequestWithContext (r * http.Request , opts ... RequestOption ) (* http.Request , error ) {
99107 _ , fc , err2 := NewFrankenPHPContext (r , opts ... )
100108 if err2 != nil {
101109 return nil , err2
102110 }
103- c := context .WithValue (r .Context (), contextKey , fc )
104-
105- return r .WithContext (c ), nil
106- }
107-
108- // NewRequestWithExistingContext wraps an http request with an existing FrankenPHP request context.
109- func NewRequestWithExistingContext (r * http.Request , fc * frankenPHPContext ) (* http.Request , error ) {
110- c := context .WithValue (r .Context (), contextKey , fc )
111111
112- return r . WithContext ( c ), nil
112+ return NewRequestWithExistingContext ( r , fc ), nil
113113}
114114
115115func newDummyContext (requestPath string , opts ... RequestOption ) (* frankenPHPContext , error ) {
0 commit comments