for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Dazzle\Http\Http\Driver\Parser;
use Dazzle\Throwable\Exception\Logic\InvalidArgumentException;
use Dazzle\Http\Http\HttpRequest;
use Dazzle\Http\Http\HttpResponse;
use GuzzleHttp\Psr7;
class HttpParser implements HttpParserInterface
{
/**
* @override
* @inheritDoc
*/
public function parseRequest($message)
$data = Psr7\_parse_message($message);
$matches = [];
if (!preg_match('/^[a-zA-Z]+\s+([a-zA-Z]+:\/\/|\/).*/', $data['start-line'], $matches))
throw new InvalidArgumentException('Invalid request string');
}
$parts = explode(' ', $data['start-line'], 3);
$version = isset($parts[2]) ? explode('/', $parts[2])[1] : '1.1';
$request = new HttpRequest(
$parts[0],
$matches[1] === '/' ? Psr7\_parse_request_uri($parts[1], $data['headers']) : $parts[1],
$data['headers'],
$data['body'],
$version
);
return $matches[1] === '/' ? $request : $request->withRequestTarget($parts[1]);
public function parseResponse($message)
if (!preg_match('/^HTTP\/.* [0-9]{3} .*/', $data['start-line']))
throw new InvalidArgumentException('Invalid response string');
return new HttpResponse(
$parts[1],
explode('/', $parts[0])[1],
isset($parts[2]) ? $parts[2] : null