summaryrefslogtreecommitdiffstats
path: root/vendor/react/http/src/Middleware/RequestBodyParserMiddleware.php
diff options
context:
space:
mode:
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);
+ }
+}