HTTP Protocol Features

ZealPHP implements the full HTTP/1.1 feature set: conditional requests, content negotiation, proper method handling, and CORS.

FeatureStatusHow
HEAD method✅ Auto-mappedResponseMiddleware runs GET handler, strips body, adds Content-Length
OPTIONS method✅ Built-inReturns 204 + Allow header with all methods registered for that URI
ETag / 304✅ MiddlewareETagMiddleware generates W/"md5", returns 304 on If-None-Match hit
Gzip compression✅ OpenSwoolehttp_compression handles bodies when Accept-Encoding includes gzip
CORS✅ MiddlewareCorsMiddleware handles preflight + adds headers to every response
Redirects 301/302/307/308✅ Built-in$response->redirect($url, $status)
Cookie SameSite✅ Built-insetcookie($name, $value, ..., $samesite)
HTTP/2⚙️ ConfigurePass 'enable_http2' => true to $app->run() (requires TLS)
Range requests⏳ PlannedUse 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 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 →