Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
},
"require": {
"php": "^8.1",
"phrity/http": "^1.0",
"nyholm/psr7": "^1.4",
"phrity/http": "^1.1",
"phrity/net-uri": "^2.1",
"phrity/net-stream": "^2.3",
"psr/http-message": "^1.1 | ^2.0",
"psr/http-message": "^1.1 || ^2.0",
"psr/log": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"guzzlehttp/psr7": "^2.0",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^10.0 || ^11.0 || ^12.0",
"phrity/logger-console": "^1.0",
"phrity/net-mock": "^2.3",
"phrity/util-errorhandler": "^1.1",
"robiningelbrecht/phpunit-coverage-tools": "^1.9",
"squizlabs/php_codesniffer": "^3.5 || ^4.0"
"squizlabs/php_codesniffer": "^4.0"
},
"suggests": {
"ext-zlib": "Required for per-message deflate compression"
Expand Down
760 changes: 392 additions & 368 deletions docs/Class_Synopsis.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ protected function performHandshake(Uri $uri, Connection $connection): ResponseI
$request = $connection->pushHttp($request);
/** @var ResponseInterface */
$response = $connection->pullHttp();

if ($response->getStatusCode() != 101) {
throw new HandshakeException("Invalid status code {$response->getStatusCode()}.", $response);
}
Expand Down Expand Up @@ -652,6 +651,7 @@ protected function parseUri(UriInterface|string $uri): Uri
if (!$uriInstance->getHost()) {
throw new BadUriException("Invalid URI host.");
}
$uriInstance = $uriInstance->withPath($uriInstance->getPath(), Uri::ABSOLUTE_PATH | Uri::NORMALIZE_PATH);
return $uriInstance;
}

Expand Down
17 changes: 10 additions & 7 deletions src/Http/HttpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

namespace WebSocket\Http;

use Phrity\Http\HttpFactory;
use Phrity\Http\{
HttpFactory,
Serializer,
};
use Phrity\Net\{
SocketStream,
Uri
};
use Psr\Http\Message\{
MessageInterface,
RequestInterface,
ResponseFactoryInterface,
ServerRequestFactoryInterface,
UriFactoryInterface,
Expand All @@ -38,6 +42,7 @@ class HttpHandler implements LoggerAwareInterface, Stringable
private SocketStream $stream;
private bool $ssl;
private HttpFactory $httpFactory;
private Serializer $serializer;

public function __construct(
SocketStream $stream,
Expand All @@ -47,6 +52,7 @@ public function __construct(
$this->stream = $stream;
$this->ssl = $ssl;
$this->httpFactory = $httpFactory ?? new DefaultHttpFactory();
$this->serializer = new Serializer();
}

/**
Expand All @@ -68,9 +74,9 @@ public function pull(): MessageInterface
// Pulling server request
preg_match('!^(?P<method>[A-Z]+) (?P<path>[^ ]*) HTTP/(?P<version>[0-9/.]+)!', $status, $matches);
if (!empty($matches)) {
$message = $this->httpFactory->createServerRequest($matches['method'], '');
$path = $matches['path'];
$version = $matches['version'];
$message = $this->httpFactory->createServerRequest($matches['method'], $path);
}

// Pulling response
Expand Down Expand Up @@ -98,7 +104,7 @@ public function pull(): MessageInterface
}
}
}
if ($message instanceof Request) {
if ($message instanceof RequestInterface) {
$scheme = $this->ssl ? 'wss' : 'ws';
$uri = $this->httpFactory->createUri("{$scheme}://{$message->getHeaderLine('Host')}{$path}");
$message = $message->withUri($uri, true);
Expand All @@ -114,10 +120,7 @@ public function pull(): MessageInterface
*/
public function push(MessageInterface $message): MessageInterface
{
if (!$message instanceof Message) {
throw new RuntimeException('Generic MessageInterface currently not supported.');
}
$data = implode("\r\n", $message->getAsArray()) . "\r\n\r\n";
$data = $this->serializer->message($message);
$this->stream->write($data);
return $message;
}
Expand Down
185 changes: 0 additions & 185 deletions src/Http/Message.php

This file was deleted.

Loading