- Can I install guhemama/http-precondition-bundle in a Laravel application?
- No. It is a Symfony bundle that registers through BundleInterface and hooks the kernel.request event of Symfony's event-driven HttpKernel, and Laravel has neither a bundle registry nor that dispatch pipeline. Laravel pulls symfony/http-kernel only transitively for HttpKernelInterface and HttpExceptionInterface, so there is no drop-in surface. What transfers is the concept of declarative per-route preconditions, and that maps onto Laravel middleware or a Route macro.
- Does this package support Laravel 10 or Laravel 11?
- There is no Laravel support and none is planned in the package itself. Laravel 10 and 11 ship symfony/http-kernel ^6.2 and ^7.0, while a bundle last released in January 2023 may cap its constraint at ^5.4 or ^6.0, producing a Composer conflict. That is moot under the recommended path because you consume the source, not the package.
- How do I handle If-None-Match and If-Modified-Since conditional requests in Laravel?
- Write a middleware that compares the request's If-None-Match header against the response ETag, and If-Modified-Since against Last-Modified, before the controller work is done. Return 304 Not Modified with the validators still attached when the client's copy is current, and 412 Precondition Failed for If-Match and If-Unmodified-Since mismatches. The bundle's matcher and evaluator can be forked into app/Http/Middleware/PreconditionMiddleware.php as a starting point.
- What is the difference between a 304 Not Modified and a 412 Precondition Failed response?
- 304 Not Modified answers a cache-validation request: the client already holds the representation and the origin is telling it to reuse it. 412 Precondition Failed means a precondition the client asserted, such as If-Match against a specific ETag, did not hold, so the request was not performed. RFC 9110 defines both in the context of conditional requests and validators, not as general-purpose route guards.
- Is it a good idea to return 412 Precondition Failed for authorization or feature-flag route checks?
- Usually not. Repurposing 412 for arbitrary route preconditions invites misbehavior from HTTP caches, CDNs and client retry logic that expect the code to mean a validator mismatch. For authorization use 403, for state conflicts use 409, and for validation-style failures use 422. Reserve 412 for genuine RFC 9110 conditional requests.
- Is guhemama/http-precondition-bundle actively maintained and safe for production?
- The signals are weak: two stars, zero dependents, a single maintainer, and a last release dated 2023-01-06. There is no downstream validation and the security posture is unknown, so supply-chain risk is the dominant concern. Treat the repository as a reference implementation to read, not a dependency to ship.
- How long does it take to port this bundle's logic to Laravel middleware?
- The reusable logic is small: a request matcher, an expression evaluator, a listener and a response factory. Budget one to two engineer-days for a spike plus a tested port. The condition-evaluation half survives intact because symfony/expression-language is a standalone component that works fine inside Laravel; only the kernel wiring has to be rewritten.
- Does the bundle use symfony/expression-language, and is that safe inside Laravel?
- The evaluation notes flag expression-based precondition declarations, and symfony/expression-language ^6 can be required directly in a Laravel app if you keep the DSL. The risk is that an unsandboxed evaluator over route definitions becomes an injection surface whenever the definition source is not fully trusted. Confirm with the maintainer whether the evaluator is sandboxed and which variables are in scope before adopting the DSL.
- What Laravel features already cover the route precondition use case?
- Most stated needs are handled by FormRequest::authorize(), the can: route middleware, signed and throttle middleware, route-model binding, and custom validation rules. The only capability the bundle adds that Laravel lacks out of the box is declarative per-route expressions paired with a uniform response code. Port the DSL only if you specifically need that combination.
- How should I test conditional request handling after porting it to Laravel?
- Write feature tests that assert the status code, the short-circuit point before the controller runs, and the behaviour when a precondition raises an exception. Cover matching and non-matching ETag and Last-Modified values, and confirm validators are still present on 304 responses. Test the 412 path separately if you keep that code for If-Match and If-Unmodified-Since.