File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace rabbit \httpserver \middleware ;
5+
6+ use Psr \Http \Message \ResponseInterface ;
7+ use Psr \Http \Message \ServerRequestInterface ;
8+ use Psr \Http \Server \MiddlewareInterface ;
9+ use Psr \Http \Server \RequestHandlerInterface ;
10+ use rabbit \core \Context ;
11+
12+ /**
13+ * Class HealthCheckMiddleware
14+ * @package rabbit\httpserver\middleware
15+ */
16+ class HealthCheckMiddleware implements MiddlewareInterface
17+ {
18+ /** @var string */
19+ protected $ health ;
20+
21+ /**
22+ * ReqHandlerMiddleware constructor.
23+ * @param string|null $health
24+ */
25+ public function __construct (string $ health = '/health ' )
26+ {
27+ $ this ->health = $ health ;
28+ }
29+
30+ /**
31+ * @param ServerRequestInterface $request
32+ * @param RequestHandlerInterface $handler
33+ * @return ResponseInterface
34+ */
35+ public function process (ServerRequestInterface $ request , RequestHandlerInterface $ handler ): ResponseInterface
36+ {
37+ $ url = $ request ->getUri ()->getPath ();
38+ if ($ url === $ this ->health ) {
39+ return Context::get ('response ' );
40+ }
41+ return $ handler ->handle ($ request );
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments