Skip to content

Commit

Permalink
Fixing remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
legionth committed Feb 15, 2017
1 parent 2b730e9 commit dc57a12
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/ChunkedDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function close()
public function handleEnd()
{
if (!$this->closed) {
$this->handleError(new \Exception('Unexpected `end` event'));
$this->handleError(new \Exception('Unexpected end event'));
}
}

Expand All @@ -90,17 +90,17 @@ public function handleData($data)

while ($this->buffer !== '') {
if (!$this->headerCompleted) {
$positionClrf = strpos($this->buffer, static::CRLF);
$positionCrlf = strpos($this->buffer, static::CRLF);

if ($positionClrf === false) {
if ($positionCrlf === false) {
// Header shouldn't be bigger than 1024 bytes
if (isset($this->buffer[static::MAX_CHUNK_HEADER_SIZE])) {
$this->handleError(new \Exception('Chunk header size inclusive extension bigger than 1024 bytes'));
$this->handleError(new \Exception('Chunk header size inclusive extension bigger than' . static::MAX_CHUNK_HEADER_SIZE. ' bytes'));
}
return;
}

$header = strtolower((string)substr($this->buffer, 0, $positionClrf));
$header = strtolower((string)substr($this->buffer, 0, $positionCrlf));
$hexValue = $header;

if (strpos($header, ';') !== false) {
Expand All @@ -114,7 +114,7 @@ public function handleData($data)
return;
}

$this->buffer = (string)substr($this->buffer, $positionClrf + 2);
$this->buffer = (string)substr($this->buffer, $positionCrlf + 2);
$this->headerCompleted = true;
if ($this->buffer === '') {
return;
Expand All @@ -129,7 +129,9 @@ public function handleData($data)
$this->buffer = (string)substr($this->buffer, strlen($chunk));
}

if (strpos($this->buffer, static::CRLF) === 0) {
$positionCrlf = strpos($this->buffer, static::CRLF);

if ($positionCrlf === 0) {
if ($this->chunkSize === 0) {
$this->emit('end');
$this->close();
Expand All @@ -139,11 +141,15 @@ public function handleData($data)
$this->headerCompleted = false;
$this->transferredSize = 0;
$this->buffer = (string)substr($this->buffer, 2);
} else if ($this->chunkSize === $this->transferredSize && strlen($this->buffer) > 2) {
}

if ($positionCrlf !== 0 && $this->chunkSize === $this->transferredSize && strlen($this->buffer) > 2) {
// the first 2 characters are not CLRF, send error event
$this->handleError(new \Exception('Chunk does not end with a CLRF'));
return;
} else if (strlen($this->buffer) < 2) {
}

if ($positionCrlf !== 0 && strlen($this->buffer) < 2) {
// No CLRF found, wait for additional data which could be a CLRF
return;
}
Expand Down

0 comments on commit dc57a12

Please sign in to comment.