Skip to content

Commit 730a5b9

Browse files
author
peter
committed
Merge remote-tracking branch 'origin/main' into main
2 parents 49212d9 + 216b570 commit 730a5b9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

app/Controller/IndexController.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
namespace App\Controller;
1212

1313
use App\Kernel\Log\Log;
14+
use Hyperf\HttpServer\Annotation\AutoController;
15+
use Hyperf\HttpServer\Annotation\Controller;
16+
use Hyperf\HttpServer\Annotation\RequestMapping;
1417

18+
#[Controller]
1519
class IndexController extends AbstractController
1620
{
1721
public function index()
@@ -27,4 +31,21 @@ public function index()
2731
'message' => "Hello {$user}.",
2832
];
2933
}
34+
#[RequestMapping(path: "test2",methods: "post")]
35+
public function test2()
36+
{
37+
return [
38+
'aa'=>11
39+
];
40+
}
41+
42+
protected function test()
43+
{
44+
echo 1111;
45+
}
46+
47+
private function foo()
48+
{
49+
echo 2222;
50+
}
3051
}

app/Middleware/CoreMiddleware.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use App\Util\RuntimeCalculator;
1414
use Hyperf\Context\Context;
1515
use Hyperf\Contract\StdoutLoggerInterface;
16+
use Hyperf\HttpMessage\Exception\MethodNotAllowedHttpException;
1617
use Hyperf\HttpMessage\Stream\SwooleStream;
1718
use Hyperf\HttpServer\Router\Dispatched;
1819
use Psr\Container\ContainerExceptionInterface;
@@ -68,6 +69,26 @@ protected function handleNotFound(ServerRequestInterface $request): mixed
6869
return $this->response()->withStatus(404);
6970
}
7071

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+
7192
/**
7293
* @throws ContainerExceptionInterface
7394
* @throws NotFoundExceptionInterface

0 commit comments

Comments
 (0)