public function parse($content) { $result = array(); $parser = uv_http_parser_init(\UV::HTTP_REQUEST); //set up http parser uv_http_parser_execute($parser, $content, $result); return $result; }
public function __invoke(ServiceManagerInterface $serviceManager, array $moreParams = []) { if (!isset($moreParams['buffer'])) { throw new Exception\UnexpectedValueException('Could not parse request.'); } $result = []; if (!\uv_http_parser_execute(\uv_http_parser_init(\UV::HTTP_REQUEST), $moreParams['buffer'], $result)) { throw new Exception\UnexpectedValueException('Could not parse request.'); } if (!isset($result['REQUEST_METHOD'])) { throw new Exception\BadRequestException('No request method found or this method is not supported.'); } if (!isset($result['PATH'])) { throw new Exception\BadRequestException('Invalid request path specified.'); } $request = new Request($result['REQUEST_METHOD'], $result['PATH']); $method = $result['REQUEST_METHOD']; if (!in_array($method, ['GET', 'HEAD']) && isset($result['HEADERS']) && isset($result['HEADERS']['BODY'])) { $postData = []; parse_str($result['HEADERS']['BODY'], $postData); $request->setPostParams(new ArrayObject($postData)); } if (isset($result['QUERY'])) { $queryData = []; parse_str($result['QUERY'], $queryData); $request->setQueryParams(new ArrayObject($queryData)); } if (isset($result['HEADERS'])) { $request->setHeaders(new ArrayObject($result['HEADERS'])); if (isset($result['HEADERS']['COOKIE'])) { $cookieData = []; parse_str($result['HEADERS']['COOKIE'], $cookieData); $request->setCookieParams(new ArrayObject($cookieData)); } } return $request; }
public function onConnect($server, $status) { $client = uv_tcp_init(); uv_tcp_nodelay($client, 1); uv_accept($server, $client); $this->clients[(int) $client] = $client; $this->parsers[(int) $client] = uv_http_parser_init(); uv_read_start($client, array($this, "onRead")); }
# # # # # # # # # ## # # # # ## # # # # # ##### ##### # # # ##### # # http server started on port {$port} EOF; echo $banner; $server = uv_tcp_init(); uv_tcp_bind6($server, uv_ip6_addr($address, $port)); $clients = array(); $parsers = array(); uv_listen($server, 511, function ($server_stream) use(&$parsers, &$clients) { $client = uv_tcp_init(); uv_accept($server_stream, $client); $clients[(int) $client] = $client; $parsers[(int) $client] = uv_http_parser_init(); uv_read_start($client, function ($client, $nread, $buffer) use(&$parsers, &$clients) { if ($nread < 0) { uv_shutdown($client, function ($client) use(&$parsers, &$clients) { uv_close($client, function ($client) use(&$parsers, &$clients) { unset($parsers[(int) $client]); unset($clients[(int) $client]); }); }); return; } else { if ($nread == 0) { if (uv_last_error() == UV::EOF) { uv_shutdown($client, function ($client) use(&$parsers, &$clients) { uv_close($client, function ($client) use(&$parsers, &$clients) { unset($parsers[(int) $client]);