nette/http
Nette HTTP is a lightweight PHP library for handling HTTP requests and responses. It provides clean APIs for headers, cookies, sessions, URL parsing, file uploads, and response output, making it easy to build robust web applications and services.
Strengths:
UrlValidator, IPAddress), cookie hardening (type-safe SameSite enum, Partitioned support, Secure auto-enforcement), and same-site request detection (Request::isFrom()). This aligns perfectly with modern Laravel security best practices (e.g., CSRF, XSS, SSRF mitigation).UrlImmutable, IPAddress, and Request immutability reduce side-effect risks in concurrent Laravel applications (e.g., queue workers, background jobs).Url/UrlImmutable classes with RFC-compliant parsing (e.g., getOrigin(), parseQuery()) can replace Laravel’s Illuminate\Support\Str or Illuminate\Routing\UrlGenerator for edge cases (e.g., IDN domains, query string validation).readAndClose, autoStart, Partitioned cookies) complements Laravel’s session drivers (e.g., Redis, database).Gaps:
Kernel.php integration). Requires custom glue code.Illuminate\Http\Request/Response are tightly coupled with the framework’s routing, middleware, and validation systems. This package’s abstractions may not directly replace them but could augment them (e.g., for security layers).TrustProxies, VerifyCsrfToken). Would need to be wrapped in Laravel middleware classes.Illuminate\Events\Dispatcher) isn’t leveraged here, requiring manual event emission if needed.v3.3.x (supports PHP 8.1–8.5). For PHP 7.4–8.0, v2.4.x is an option but lacks modern features.Request::getOrigin() for CORS, UrlValidator for API gateways).Response::setCookie() with SameSite/Secure/Partitioned support can harden Laravel’s cookie system (e.g., for third-party analytics).FileUpload class offers stricter sanitization than Laravel’s Illuminate\Http\UploadedFile (e.g., getSanitizedName(), image extension validation).SessionExtension for advanced features like readAndClose.UrlValidator in a Laravel middleware to validate outbound HTTP requests (e.g., API calls, redirects):
public function handle(Request $request, Closure $next) {
$validator = new UrlValidator(['allow' => ['https://trusted.com']]);
if (!$validator->validate($request->url)) {
abort(400, 'Invalid URL');
}
return $next($request);
}
Nette\Http\IRequest) to Laravel’s Request:
public function register() {
$this->app->bind(IRequest::class, function () {
return new RequestFactory()->createRequest();
});
}
UserStorage, Request::getRemoteHost(), getReferer(), and SessionSection magic methods are removed or deprecated. Audit existing code for usage.SameSite enum replaces constants; setCookie() now auto-enforces Secure for SameSite=None.UrlValidator must be strictly configured to avoid false positives/negatives. Test with edge cases (e.g., IPv6, Unicode domains).Session::autoStart(false) prevents session fixation but may break legacy Laravel session handling.Response::setCookie() may conflict with Laravel’s Cookie::queue() if not coordinated.UrlValidator with DNS resolution adds latency. Cache resolved IPs if used frequently.UrlImmutable/IPAddress may increase memory usage for high-throughput APIs.Request::isFrom() falls back to cookies for Safari <16.4. Test cross-browser behavior.Url::parseQuery() with malformed input (e.g., ?key=value;key2=value2).UrlValidator’s DNS resolution interact with Laravel’s caching layer (e.g., Illuminate\Cache)?SameSite=None cookies be allowed, or enforce SameSite=Lax by default?Request/Response entirely, or augment them (e.g., for security middleware)?session() helper and SessionGuard?IPAddress validation in high-QPS APIs (e.g., 10k+ RPS)?UrlImmutable be cached for repeated URL operations?Request/Response APIs diverge from this package’s interfaces?getRemoteHost()) be phased out in existing Laravel code?Secure, HttpOnly, SameSite)?Partitioned cookies affect third-party analytics vendors?Illuminate\Http\Request’s parsing logic with Nette\Http\Request for:
UrlValidator for API endpoints).Request::getOrigin() for CORS).FileUpload::getSanitizedName()).Illuminate\Http\Response with Nette\Http\Response for:
SameSite, Partitioned, Max-Age).Secure for SameSite=None).Nette\Http\Session with Laravel’s session drivers (e.g., Redis) for:
readAndClose mode to reduce session storage overhead.Partitioned cookies for third-party session sharing.UrlValidator to validate:
SameSite=Lax for all cookies.Illuminate\Validation\Validator for URL/email validation with UrlValidator/IPAddress.| Phase | Action | Tools/Leverage | Risk |
|---|---|---|---|
| Assessment | Audit Laravel code for Request/Response/Session usage. |
PHPStan, Psalm, Laravel Pint. | Low (static analysis). |
| Pilot | Replace Request parsing in a single module (e.g., API controller). |
Laravel’s app()->bind() for DI. |
Medium (feature parity testing). |
| Core | Extend Illuminate\Http\Request with ` |
How can I help you explore Laravel packages today?