summaryrefslogtreecommitdiffstats
path: root/vendor/react/http/src/Middleware/RequestBodyParserMiddleware.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:38:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:38:42 +0000
commitc3ca98e1b35123f226c7f4c596b5dee78caa4223 (patch)
tree9b6eb109283da55e7d9064baa9fac795a40264cb /vendor/react/http/src/Middleware/RequestBodyParserMiddleware.php
parentInitial commit. (diff)
downloadicinga-php-thirdparty-c3ca98e1b35123f226c7f4c596b5dee78caa4223.tar.xz
icinga-php-thirdparty-c3ca98e1b35123f226c7f4c596b5dee78caa4223.zip
Adding upstream version 0.11.0.upstream/0.11.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/react/http/src/Middleware/RequestBodyParserMiddleware.php')
-rw-r--r--vendor/react/http/src/Middleware/RequestBodyParserMiddleware.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/react/http/src/Middleware/RequestBodyParserMiddleware.php b/vendor/react/http/src/Middleware/RequestBodyParserMiddleware.php
new file mode 100644
index 0000000..be5ba16
--- /dev/null
+++ b/vendor/react/http/src/Middleware/RequestBodyParserMiddleware.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace React\Http\Middleware;
+
+use Psr\Http\Message\ServerRequestInterface;
+use React\Http\Io\MultipartParser;
+
+final class RequestBodyParserMiddleware
+{
+ private $multipart;
+
+ /**
+ * @param int|string|null $uploadMaxFilesize
+ * @param int|null $maxFileUploads
+ */
+ public function __construct($uploadMaxFilesize = null, $maxFileUploads = null)
+ {
+ $this->multipart = new MultipartParser($uploadMaxFilesize, $maxFileUploads);
+ }
+
+ public function __invoke(ServerRequestInterface $request, $next)
+ {
+ $type = \strtolower($request->getHeaderLine('Content-Type'));
+ list ($type) = \explode(';', $type);
+
+ if ($type === 'application/x-www-form-urlencoded') {
+ return $next($this->parseFormUrlencoded($request));
+ }
+
+ if ($type === 'multipart/form-data') {
+ return $next($this->multipart->parse($request));
+ }
+
+ return $next($request);
+ }
+
+ private function parseFormUrlencoded(ServerRequestInterface $request)
+ {
+ // parse string into array structure
+ // ignore warnings due to excessive data structures (max_input_vars and max_input_nesting_level)
+ $ret = array();
+ @\parse_str((string)$request->getBody(), $ret);
+
+ return $request->withParsedBody($ret);
+ }
+}