Skip to content

Commit 3674149

Browse files
authored
Support swow psr7-plus interface for all components. (#5839)
1 parent 75c3d1e commit 3674149

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/CoreMiddleware.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
namespace Hyperf\WebSocketServer;
1313

14-
use Hyperf\Context\Context;
14+
use Hyperf\Context\ResponseContext;
1515
use Hyperf\HttpMessage\Base\Response;
1616
use Hyperf\HttpServer\CoreMiddleware as HttpCoreMiddleware;
1717
use Hyperf\HttpServer\Router\Dispatched;
@@ -34,16 +34,16 @@ protected function handleFound(Dispatched $dispatched, ServerRequestInterface $r
3434
}
3535

3636
/** @var Response $response */
37-
$response = Context::get(ResponseInterface::class);
37+
$response = ResponseContext::get();
3838

3939
$security = $this->container->get(Security::class);
4040

4141
$key = $request->getHeaderLine(Security::SEC_WEBSOCKET_KEY);
42-
$response = $response->withStatus(101)->withHeaders($security->handshakeHeaders($key));
42+
$response = $response->setStatus(101)->setHeaders($security->handshakeHeaders($key));
4343
if ($wsProtocol = $request->getHeaderLine(Security::SEC_WEBSOCKET_PROTOCOL)) {
44-
$response = $response->withHeader(Security::SEC_WEBSOCKET_PROTOCOL, $wsProtocol);
44+
$response = $response->setHeader(Security::SEC_WEBSOCKET_PROTOCOL, $wsProtocol);
4545
}
4646

47-
return $response->withAttribute(self::HANDLER_NAME, $controller);
47+
return $response->setAttribute(self::HANDLER_NAME, $controller);
4848
}
4949
}

src/Exception/Handler/WebSocketExceptionHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Hyperf\ExceptionHandler\Formatter\FormatterInterface;
1717
use Hyperf\HttpMessage\Exception\HttpException;
1818
use Hyperf\HttpMessage\Stream\SwooleStream;
19-
use Psr\Http\Message\ResponseInterface;
19+
use Swow\Psr7\Message\ResponsePlusInterface;
2020
use Throwable;
2121

2222
class WebSocketExceptionHandler extends ExceptionHandler
@@ -25,14 +25,14 @@ public function __construct(protected StdoutLoggerInterface $logger, protected F
2525
{
2626
}
2727

28-
public function handle(Throwable $throwable, ResponseInterface $response)
28+
public function handle(Throwable $throwable, ResponsePlusInterface $response)
2929
{
3030
$this->logger->warning($this->formatter->format($throwable));
3131
if ($throwable instanceof HttpException) {
32-
$response = $response->withStatus($throwable->getStatusCode());
32+
$response = $response->setStatus($throwable->getStatusCode());
3333
}
3434
$stream = new SwooleStream($throwable->getMessage());
35-
return $response->withBody($stream);
35+
return $response->setBody($stream);
3636
}
3737

3838
public function isValid(Throwable $throwable): bool

0 commit comments

Comments
 (0)