Skip to content

Commit

Permalink
Merge pull request #59 from clue-labs/clean
Browse files Browse the repository at this point in the history
Revert blocking and GPL-licensed code
  • Loading branch information
WyriHaximus authored Aug 20, 2016
2 parents cd15204 + f0000a5 commit ef71d49
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 862 deletions.
203 changes: 0 additions & 203 deletions src/MultipartParser.php

This file was deleted.

52 changes: 4 additions & 48 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,21 @@ class Request extends EventEmitter implements ReadableStreamInterface
{
private $readable = true;
private $method;
private $url;
private $path;
private $query;
private $httpVersion;
private $headers;
private $body;
private $post = [];
private $files = [];

// metadata, implicitly added externally
public $remoteAddress;

public function __construct($method, $url, $query = array(), $httpVersion = '1.1', $headers = array(), $body = '')
public function __construct($method, $path, $query = array(), $httpVersion = '1.1', $headers = array())
{
$this->method = $method;
$this->url = $url;
$this->path = $path;
$this->query = $query;
$this->httpVersion = $httpVersion;
$this->headers = $headers;
$this->body = $body;
}

public function getMethod()
Expand All @@ -39,12 +35,7 @@ public function getMethod()

public function getPath()
{
return $this->url->getPath();
}

public function getUrl()
{
return $this->url;
return $this->path;
}

public function getQuery()
Expand All @@ -62,41 +53,6 @@ public function getHeaders()
return $this->headers;
}

public function getBody()
{
return $this->body;
}

public function setBody($body)
{
$this->body = $body;
}

public function getFiles()
{
return $this->files;
}

public function setFiles($files)
{
$this->files = $files;
}

public function getPost()
{
return $this->post;
}

public function setPost($post)
{
$this->post = $post;
}

public function getRemoteAddress()
{
return $this->remoteAddress;
}

public function expectsContinue()
{
return isset($this->headers['Expect']) && '100-continue' === $this->headers['Expect'];
Expand Down
65 changes: 65 additions & 0 deletions src/RequestHeaderParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace React\Http;

use Evenement\EventEmitter;
use GuzzleHttp\Psr7 as g7;

/**
* @event headers
* @event error
*/
class RequestHeaderParser extends EventEmitter
{
private $buffer = '';
private $maxSize = 4096;

public function feed($data)
{
if (strlen($this->buffer) + strlen($data) > $this->maxSize) {
$this->emit('error', array(new \OverflowException("Maximum header size of {$this->maxSize} exceeded."), $this));

return;
}

$this->buffer .= $data;

if (false !== strpos($this->buffer, "\r\n\r\n")) {
list($request, $bodyBuffer) = $this->parseRequest($this->buffer);

$this->emit('headers', array($request, $bodyBuffer));
$this->removeAllListeners();
}
}

public function parseRequest($data)
{
list($headers, $bodyBuffer) = explode("\r\n\r\n", $data, 2);

$psrRequest = g7\parse_request($headers);

$parsedQuery = [];
$queryString = $psrRequest->getUri()->getQuery();
if ($queryString) {
parse_str($queryString, $parsedQuery);
}

$headers = array_map(function($val) {
if (1 === count($val)) {
$val = $val[0];
}

return $val;
}, $psrRequest->getHeaders());

$request = new Request(
$psrRequest->getMethod(),
$psrRequest->getUri()->getPath(),
$parsedQuery,
$psrRequest->getProtocolVersion(),
$headers
);

return array($request, $bodyBuffer);
}
}
Loading

0 comments on commit ef71d49

Please sign in to comment.