Skip to content

Conversation

@AlliBalliBaba
Copy link
Contributor

@AlliBalliBaba AlliBalliBaba commented Sep 4, 2025

This PR removes NewRequestWithContext (slight breaking change for library users).

Instead of:

req, err1 := frankenphp.NewRequestWithContext(r, opts...) // no benefit to doing this currently
err2 := frankenphp.ServeHTTP(w, req)

Just:

err := frankenphp.ServeHTTP(w, r, opts...)

@AlliBalliBaba AlliBalliBaba marked this pull request as ready for review September 4, 2025 21:29
@dunglas
Copy link
Member

dunglas commented Sep 8, 2025

Can we just deprecate the old symbol and explain in the docs that it is useless? No need to break existing code for this IMHO.

@AlliBalliBaba
Copy link
Contributor Author

Alright, NewRequestWithContext is added back in as deprecated with a test to make sure it still works.


// ServeHTTP executes a PHP script according to the given context.
func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request, opts ...RequestOption) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding a new parameter instead of using the request context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way we only need to expose 1 function instead of 2 and don't have to do the additional allocation via the context. It's more about clarity though, directly passing a request with options just leaves less room for errors.

@dunglas
Copy link
Member

dunglas commented Nov 17, 2025

Another problem with this approach is that it's not possible anymore to expose some public custom values through the context to the calling code. It's a common practice for logging, tracing etc, for instance.

TBH, I'm not sure this change is worth it.

@AlliBalliBaba
Copy link
Contributor Author

Not yet sure if exposing values via context is even a good idea, so I might revive a version of this at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants