改名
This commit is contained in:
@@ -16,88 +16,100 @@ namespace HttpServer\Http;
|
||||
trait HttpHeaders
|
||||
{
|
||||
|
||||
private array $_headers = [];
|
||||
private array $_headers = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param array $headers
|
||||
*/
|
||||
public function setHeaders(array $headers): void
|
||||
{
|
||||
$this->_headers = $headers;
|
||||
}
|
||||
/**
|
||||
* @param array $headers
|
||||
*/
|
||||
public function setHeaders(array $headers): void
|
||||
{
|
||||
$this->_headers = $headers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getHeader($name, $default = null): mixed
|
||||
{
|
||||
return $this->_headers[$name] ?? $default;
|
||||
}
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function getHeader($name, $default = null): mixed
|
||||
{
|
||||
return $this->_headers[$name] ?? $default;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContentType(): string
|
||||
{
|
||||
return $this->_headers['content-type'] ?? '';
|
||||
}
|
||||
/**
|
||||
* @param $name
|
||||
* @param $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function header($name, $default = null): mixed
|
||||
{
|
||||
return $this->getHeader($name, $default);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRequestUri(): ?string
|
||||
{
|
||||
return $this->_headers['request_uri'];
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContentType(): string
|
||||
{
|
||||
return $this->_headers['content-type'] ?? '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRequestMethod(): ?string
|
||||
{
|
||||
return $this->_headers['request_method'];
|
||||
}
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRequestUri(): ?string
|
||||
{
|
||||
return $this->_headers['request_uri'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAgent(): mixed
|
||||
{
|
||||
return $this->_headers['user-agent'];
|
||||
}
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRequestMethod(): ?string
|
||||
{
|
||||
return $this->_headers['request_method'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($name): bool
|
||||
{
|
||||
return $this->_headers[$name] ?? null === null;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAgent(): mixed
|
||||
{
|
||||
return $this->_headers['user-agent'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
/**
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($name): bool
|
||||
{
|
||||
return $this->_headers[$name] ?? null === null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use HttpServer\Http\Context;
|
||||
use HttpServer\Http\Request;
|
||||
use HttpServer\Http\Response;
|
||||
use HttpServer\IInterface\Middleware;
|
||||
use Server\RequestInterface;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
@@ -32,15 +33,13 @@ class CoreMiddleware implements Middleware
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onHandler(Request $request, Closure $next): mixed
|
||||
public function onHandler(RequestInterface $request, Closure $next): mixed
|
||||
{
|
||||
$headers = $request->headers;
|
||||
|
||||
/** @var Response $response */
|
||||
$response = Snowflake::getApp('response');
|
||||
$response->addHeader('Access-Control-Allow-Origin', '*');
|
||||
$response->addHeader('Access-Control-Allow-Headers', $headers->get('access-control-request-headers'));
|
||||
$response->addHeader('Access-Control-Request-Method', $headers->get('access-control-request-method'));
|
||||
$response->addHeader('Access-Control-Allow-Headers', $request->header('access-control-request-headers'));
|
||||
$response->addHeader('Access-Control-Request-Method', $request->header('access-control-request-method'));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user