index/src/Http/Headers/KeepAliveHeader.php

44 lines
1 KiB
PHP

<?php
// KeepAliveHeader.php
// Created: 2022-02-14
// Updated: 2022-02-15
namespace Index\Http\Headers;
use Index\Http\HttpHeader;
class KeepAliveHeader {
private int $timeOut;
private int $max;
public function __construct(int $timeOut, int $max) {
$this->timeOut = $timeOut;
$this->max = $max;
}
public function getTimeOut(): int {
return $this->timeOut;
}
public function getMax(): int {
return $this->max;
}
public static function parse(HttpHeader $header): KeepAliveHeader {
$params = explode(',', $header->getFirstLine());
$timeOut = -1;
$max = -1;
foreach($params as $param) {
if(str_starts_with($param, 'timeout='))
$timeOut = intval(substr($param, 8));
elseif(str_starts_with($param, 'max='))
$max = intval(substr($param, 4));
if($timeOut >= 0 && $max >= 0)
break;
}
return new KeepAliveHeader($timeOut, $max);
}
}