Skip to content

Commit

Permalink
fix Route annotation wrong response bug
Browse files Browse the repository at this point in the history
  • Loading branch information
crazywhalecc committed Feb 12, 2023
1 parent 817b81f commit a354a2f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ZM/Event/Listener/HttpEventListener.php
Expand Up @@ -8,6 +8,7 @@
use Choir\Http\Stream;
use OneBot\Driver\Event\Http\HttpRequestEvent;
use OneBot\Util\Singleton;
use Psr\Http\Message\ResponseInterface;
use ZM\Annotation\AnnotationHandler;
use ZM\Annotation\Framework\BindEvent;
use ZM\Annotation\Http\Route;
Expand Down Expand Up @@ -51,7 +52,10 @@ public function onRequest999(HttpRequestEvent $event)
// $div->request_method = $node['request_method'];
$div->class = $node['class'];
$route_handler->handle($div, null, $params, $event->getRequest(), $event);
if (is_string($val = $route_handler->getReturnVal()) || ($val instanceof \Stringable)) {
$val = $route_handler->getReturnVal();
if ($val instanceof ResponseInterface) {
$event->withResponse($val);
} elseif (is_string($val)) {
// 返回的内容是可以被字符串化的,就当作 Body 来返回,状态码 200
$event->withResponse(HttpFactory::createResponse(200, null, [], Stream::create($val)));
} elseif ($event->getResponse() === null) {
Expand Down

0 comments on commit a354a2f

Please sign in to comment.