Final Class Yiisoft\Csrf\CsrfHeaderMiddleware
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Psr\ |
PSR-15 middleware that takes care of custom HTTP header CSRF validation.
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| HEADER_NAME | 'X-CSRF-Header' | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $responseFactory | \ |
|
| $failureHandler | ?\ |
|
public function __construct(
ResponseFactoryInterface $responseFactory,
?RequestHandlerInterface $failureHandler = null
) {
$this->responseFactory = $responseFactory;
$this->failureHandler = $failureHandler;
}
| public string getHeaderName ( ) |
public function getHeaderName(): string
{
return $this->headerName;
}
| public \ | ||
| $request | \ |
|
| $handler | \ |
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($this->validateCsrfToken($request)) {
return $handler->handle($request);
}
if ($this->failureHandler !== null) {
return $this->failureHandler->handle($request);
}
$response = $this->responseFactory->createResponse(Status::UNPROCESSABLE_ENTITY);
$response
->getBody()
->write(Status::TEXTS[Status::UNPROCESSABLE_ENTITY]);
return $response;
}
| public self withHeaderName ( string $name ) | ||
| $name | string | |
public function withHeaderName(string $name): self
{
$new = clone $this;
$new->headerName = $name;
return $new;
}
| public self withUnsafeMethods ( array $methods ) | ||
| $methods | array |
"unsafe" methods not triggered a CORS-preflight request |
public function withUnsafeMethods(array $methods): self
{
$new = clone $this;
$new->unsafeMethods = $methods;
return $new;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.