-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from clue-labs/clean
Revert blocking and GPL-licensed code
- Loading branch information
Showing
9 changed files
with
208 additions
and
862 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.