Skip to content

Commit ef71d49

Browse files
authored
Merge pull request #59 from clue-labs/clean
Revert blocking and GPL-licensed code
2 parents cd15204 + f0000a5 commit ef71d49

File tree

9 files changed

+208
-862
lines changed

9 files changed

+208
-862
lines changed

src/MultipartParser.php

Lines changed: 0 additions & 203 deletions
This file was deleted.

src/Request.php

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,21 @@ class Request extends EventEmitter implements ReadableStreamInterface
1111
{
1212
private $readable = true;
1313
private $method;
14-
private $url;
14+
private $path;
1515
private $query;
1616
private $httpVersion;
1717
private $headers;
18-
private $body;
19-
private $post = [];
20-
private $files = [];
2118

2219
// metadata, implicitly added externally
2320
public $remoteAddress;
2421

25-
public function __construct($method, $url, $query = array(), $httpVersion = '1.1', $headers = array(), $body = '')
22+
public function __construct($method, $path, $query = array(), $httpVersion = '1.1', $headers = array())
2623
{
2724
$this->method = $method;
28-
$this->url = $url;
25+
$this->path = $path;
2926
$this->query = $query;
3027
$this->httpVersion = $httpVersion;
3128
$this->headers = $headers;
32-
$this->body = $body;
3329
}
3430

3531
public function getMethod()
@@ -39,12 +35,7 @@ public function getMethod()
3935

4036
public function getPath()
4137
{
42-
return $this->url->getPath();
43-
}
44-
45-
public function getUrl()
46-
{
47-
return $this->url;
38+
return $this->path;
4839
}
4940

5041
public function getQuery()
@@ -62,41 +53,6 @@ public function getHeaders()
6253
return $this->headers;
6354
}
6455

65-
public function getBody()
66-
{
67-
return $this->body;
68-
}
69-
70-
public function setBody($body)
71-
{
72-
$this->body = $body;
73-
}
74-
75-
public function getFiles()
76-
{
77-
return $this->files;
78-
}
79-
80-
public function setFiles($files)
81-
{
82-
$this->files = $files;
83-
}
84-
85-
public function getPost()
86-
{
87-
return $this->post;
88-
}
89-
90-
public function setPost($post)
91-
{
92-
$this->post = $post;
93-
}
94-
95-
public function getRemoteAddress()
96-
{
97-
return $this->remoteAddress;
98-
}
99-
10056
public function expectsContinue()
10157
{
10258
return isset($this->headers['Expect']) && '100-continue' === $this->headers['Expect'];

src/RequestHeaderParser.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace React\Http;
4+
5+
use Evenement\EventEmitter;
6+
use GuzzleHttp\Psr7 as g7;
7+
8+
/**
9+
* @event headers
10+
* @event error
11+
*/
12+
class RequestHeaderParser extends EventEmitter
13+
{
14+
private $buffer = '';
15+
private $maxSize = 4096;
16+
17+
public function feed($data)
18+
{
19+
if (strlen($this->buffer) + strlen($data) > $this->maxSize) {
20+
$this->emit('error', array(new \OverflowException("Maximum header size of {$this->maxSize} exceeded."), $this));
21+
22+
return;
23+
}
24+
25+
$this->buffer .= $data;
26+
27+
if (false !== strpos($this->buffer, "\r\n\r\n")) {
28+
list($request, $bodyBuffer) = $this->parseRequest($this->buffer);
29+
30+
$this->emit('headers', array($request, $bodyBuffer));
31+
$this->removeAllListeners();
32+
}
33+
}
34+
35+
public function parseRequest($data)
36+
{
37+
list($headers, $bodyBuffer) = explode("\r\n\r\n", $data, 2);
38+
39+
$psrRequest = g7\parse_request($headers);
40+
41+
$parsedQuery = [];
42+
$queryString = $psrRequest->getUri()->getQuery();
43+
if ($queryString) {
44+
parse_str($queryString, $parsedQuery);
45+
}
46+
47+
$headers = array_map(function($val) {
48+
if (1 === count($val)) {
49+
$val = $val[0];
50+
}
51+
52+
return $val;
53+
}, $psrRequest->getHeaders());
54+
55+
$request = new Request(
56+
$psrRequest->getMethod(),
57+
$psrRequest->getUri()->getPath(),
58+
$parsedQuery,
59+
$psrRequest->getProtocolVersion(),
60+
$headers
61+
);
62+
63+
return array($request, $bodyBuffer);
64+
}
65+
}

0 commit comments

Comments
 (0)