Skip to content

Commit

Permalink
enhancement(http): HTTP parser decodes base64 encoded content in mult…
Browse files Browse the repository at this point in the history
…ipart
  • Loading branch information
roxblnfk committed Jun 7, 2024
1 parent 382fea1 commit db60976
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Traffic/Parser/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,15 @@ public static function parseMultipartBody(StreamInterface $stream, string $bound
$findBoundary = "\r\n--{$boundary}";

if ($part instanceof File) {
$fileStream = StreamHelper::createFileStream();
$fileSize = StreamHelper::writeStreamUntil($stream, $fileStream, $findBoundary);
$part->setStream($fileStream, $fileSize);
$writeFilters = [];
if ($part->hasHeader('Content-Transfer-Encoding')) {
$encoding = $part->getHeaderLine('Content-Transfer-Encoding');
$encoding === 'base64' and $writeFilters[] = \Buggregator\Trap\Support\Stream\Base64DecodeFilter::FILTER_NAME;

Check failure on line 114 in src/Traffic/Parser/Http.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Only booleans are allowed in &&, string given on the right side.
}

$fileStream = StreamHelper::createFileStream(writeFilters: $writeFilters);
StreamHelper::writeStreamUntil($stream, $fileStream, $findBoundary);
$part->setStream($fileStream);
} elseif ($part instanceof Field) {
$endOfContent = StreamHelper::strpos($stream, $findBoundary);
$endOfContent !== false or throw new \RuntimeException('Missing end of content');
Expand Down

0 comments on commit db60976

Please sign in to comment.