HTTP Protocol Features
ZealPHP implements the full HTTP/1.1 feature set: conditional requests, content negotiation, proper method handling, and CORS.
| Feature | Status | How |
|---|---|---|
| HEAD method | ✅ Auto-mapped | ResponseMiddleware runs GET handler, strips body, adds Content-Length |
| OPTIONS method | ✅ Built-in | Returns 204 + Allow header with all methods registered for that URI |
| ETag / 304 | ✅ Middleware | ETagMiddleware generates W/"md5", returns 304 on If-None-Match hit |
| Gzip compression | ✅ OpenSwoole | http_compression handles bodies when Accept-Encoding includes gzip |
| CORS | ✅ Middleware | CorsMiddleware handles preflight + adds headers to every response |
| Redirects 301/302/307/308 | ✅ Built-in | $response->redirect($url, $status) |
| Cookie SameSite | ✅ Built-in | setcookie($name, $value, ..., $samesite) |
| HTTP/2 | ⚙️ Configure | Pass 'enable_http2' => true to $app->run() (requires TLS) |
| Range requests | ⏳ Planned | Use OpenSwoole static handler for files |
HEAD
HEAD — headers only, body stripped
// Register GET route — HEAD works automatically:
$app->route('/http/head-test', function() {
header('X-Custom-Header: zealphp');
echo str_repeat('x', 2048); // 2KB body
});
// curl -I https://php.zeal.ninja/http/head-test
// → Content-Length: 2048 (no body)
// → X-Custom-Header: zealphp
LIVE OUTPUT
Click Run →
OPTIONS — Allow header for URI
$app->route('/http/options-test', ['methods' => ['GET','POST','PUT']], fn() => '');
// curl -X OPTIONS https://php.zeal.ninja/http/options-test -v
// → HTTP/1.1 204 No Content
// → Allow: OPTIONS, GET, HEAD, POST, PUT
LIVE OUTPUT
Click Run →
GET
Redirects — 301/302/307/308
// $response->redirect() sets Location + status
$app->route('/http/redirect/{code}', function($code, $response) {
$response->redirect('/http/redirect-target', (int)$code);
});
// Auto-302 on Location header:
header('Location: https://example.com');
// ZealPHP detects Location: → sets status 302 automatically
LIVE OUTPUT
Click Run →