Always rewind input streams if possible.
This commit is contained in:
parent
2372a113d2
commit
0f3501acc6
4 changed files with 17 additions and 16 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
0.2503.230355
|
||||
0.2503.251417
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
// MultipartFormContent.php
|
||||
// Created: 2025-03-12
|
||||
// Updated: 2025-03-23
|
||||
// Updated: 2025-03-25
|
||||
|
||||
namespace Index\Http\Content;
|
||||
|
||||
|
@ -88,7 +88,7 @@ class MultipartFormContent implements FormContent, Iterator {
|
|||
/**
|
||||
* Parses multipart form data in a stream.
|
||||
*
|
||||
* @param StreamInterface $stream Stream to parse, if seekable gets rewound.
|
||||
* @param StreamInterface $stream Stream to parse.
|
||||
* @param string $boundary Boundary string.
|
||||
* @throws RuntimeException if the form could not be parsed correctly
|
||||
* @return MultipartFormContent
|
||||
|
@ -221,9 +221,6 @@ class MultipartFormContent implements FormContent, Iterator {
|
|||
$params[$part->name] = [$part];
|
||||
}
|
||||
|
||||
if($stream->isSeekable())
|
||||
$stream->rewind();
|
||||
|
||||
return new MultipartFormContent($stream, $params, $files);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
// UrlEncodedFormContent.php
|
||||
// Created: 2025-03-12
|
||||
// Updated: 2025-03-20
|
||||
// Updated: 2025-03-25
|
||||
|
||||
namespace Index\Http\Content;
|
||||
|
||||
|
@ -58,14 +58,10 @@ class UrlEncodedFormContent implements FormContent {
|
|||
/**
|
||||
* Parses URL encoded form params in a stream.
|
||||
*
|
||||
* @param StreamInterface $stream Stream to parse, if seekable gets rewound.
|
||||
* @param StreamInterface $stream Stream to parse.
|
||||
* @return UrlEncodedFormContent
|
||||
*/
|
||||
public static function parseStream(StreamInterface $stream): UrlEncodedFormContent {
|
||||
$params = HttpUri::parseQueryString((string)$stream);
|
||||
if($stream->isSeekable())
|
||||
$stream->rewind();
|
||||
|
||||
return new UrlEncodedFormContent($stream, $params);
|
||||
return new UrlEncodedFormContent($stream, HttpUri::parseQueryString((string)$stream));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
// RouterProcessors.php
|
||||
// Created: 2025-03-15
|
||||
// Updated: 2025-03-20
|
||||
// Updated: 2025-03-25
|
||||
|
||||
namespace Index\Http\Routing;
|
||||
|
||||
|
@ -23,7 +23,11 @@ class RouterProcessors implements RouteHandler {
|
|||
if(!$contentType->equals('application/x-www-form-urlencoded'))
|
||||
return false;
|
||||
|
||||
$context->deps->register(UrlEncodedFormContent::parseStream($request->getBody()));
|
||||
$stream = $request->getBody();
|
||||
if($stream->isSeekable())
|
||||
$stream->rewind();
|
||||
|
||||
$context->deps->register(UrlEncodedFormContent::parseStream($stream));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -44,7 +48,11 @@ class RouterProcessors implements RouteHandler {
|
|||
if(empty($boundary))
|
||||
return false;
|
||||
|
||||
$context->deps->register(MultipartFormContent::parseStream($request->getBody(), $boundary));
|
||||
$stream = $request->getBody();
|
||||
if($stream->isSeekable())
|
||||
$stream->rewind();
|
||||
|
||||
$context->deps->register(MultipartFormContent::parseStream($stream, $boundary));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue