-
Notifications
You must be signed in to change notification settings - Fork 24.3k
[9.x] Handle precognition requests by default #5997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello @driesvints By adding return response()->file(Storage::path($payment->attachment)); ... the middleware will try to to add the
Reference
/**
* Append the appropriate "Vary" header to the given response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Response $response
* @return \Illuminate\Http\Response $response
*/
protected function appendVaryHeader($request, $response)
{
return $response->header('Vary', implode(', ', array_filter([
$response->headers->get('Vary'),
'Precognition',
])));
}
/**
* Return the raw contents of a binary file.
*
* @param \SplFileInfo|string $file
* @param array $headers
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function file($file, array $headers = []); The FixWe can fix this by checking the instance of |
虚幻之物对应着冥冥之路!:《羽》
|
In principle I'm okay with this being applied by default, however some things we should consider:
Take this convoluted scenario: class Middleware
{
public function handle($request, $next)
{
Counter::increment($request->user());
return $next($request)
}
}
class Controller
{
public function show($request)
{
AnotherCounter::incrememt($request->user());
return response();
}
}
Route::get('foo', [Controller::class, 'show'])->middleware(Middleware::class); If the middleware is applied globally, then if it isn't considered on this route, I can open up Postman and get these counters out of sync, even if they should not be allowed to within the application i.e. this isn't a route that the front-end uses Precognition features. Perhaps for a Precognition request the intended functionality of this middleware is to not perform a side-effect: class Middleware
{
public function handle($request, $next)
{
if (! $request->isPrecognitive()) {
Counter::increment($request->user());
}
return $next($request)
}
} My point being that it is a little more developer overhead to consider on every single route / middleware. If it is opt-in it is still a very intentional thing. In principle I do support this PR, just wanna make sure we consider everything. |
@habibalkhabbaz I've already addressed the issue you raised: laravel/framework#44424 |
Thanks! |
@timacdonald what if we comment out the middleware by default? Like I've done now. |
I think it's probably mostly intended that you apply this on the routes you want to be precognitive. |
This PR adds the
HandlePrecognitiveRequests
middleware to the default middleware stack. The goal of this is to make it even more frictionless for people to get started with implementing precognition requests.Precognition requests are invoked with a
Precognition: true
header meaning apps that don't explicitly pass this aren't affected. The only thing that's left to do for users is to implement theisPrecognitive
checks in their apps. Adding the middleware on a route-per-route basis isn't needed anymore.People can still turn off this global middleware and implement on a route-per-route basis but I could not see a problem by adding this by default.