|
13 | 13 | use App\Util\RuntimeCalculator; |
14 | 14 | use Hyperf\Context\Context; |
15 | 15 | use Hyperf\Contract\StdoutLoggerInterface; |
| 16 | +use Hyperf\HttpMessage\Exception\MethodNotAllowedHttpException; |
16 | 17 | use Hyperf\HttpMessage\Stream\SwooleStream; |
17 | 18 | use Hyperf\HttpServer\Router\Dispatched; |
18 | 19 | use Psr\Container\ContainerExceptionInterface; |
@@ -68,6 +69,26 @@ protected function handleNotFound(ServerRequestInterface $request): mixed |
68 | 69 | return $this->response()->withStatus(404); |
69 | 70 | } |
70 | 71 |
|
| 72 | + /** |
| 73 | + * Handle the response when the routes found but doesn't match any available methods. |
| 74 | + */ |
| 75 | + protected function handleMethodNotAllowed(array $methods, ServerRequestInterface $request): mixed |
| 76 | + { |
| 77 | + $std = $this->stdLogger(); |
| 78 | + $std->error('REQUEST Method Not Allowed!'); |
| 79 | + $std->error('Host: ' . $request->getHeaderLine('Host')); |
| 80 | + $std->error('Method: ' . $request->getMethod()); |
| 81 | + $std->error('Allow Methods: ' . implode(', ', $methods)); |
| 82 | + $std->error('Path: ' . $request->getUri()->getPath()); |
| 83 | + $std->error('Query: ' . $request->getUri()->getQuery()); |
| 84 | + $std->error('X-Real-PORT: ' . $request->getHeaderLine('X-Real-PORT')); |
| 85 | + $std->error('X-Forwarded-For: ' . $request->getHeaderLine('X-Forwarded-For')); |
| 86 | + $std->error('x-real-ip: ' . $request->getHeaderLine('x-real-ip')); |
| 87 | + $std->error('referer: ' . $request->getHeaderLine('referer')); |
| 88 | + |
| 89 | + return $this->response()->withBody(new SwooleStream('Method Not Allowed.'))->withStatus(405); |
| 90 | + } |
| 91 | + |
71 | 92 | /** |
72 | 93 | * @throws ContainerExceptionInterface |
73 | 94 | * @throws NotFoundExceptionInterface |
|
0 commit comments