From 6ccd06911e81499a014b643ab7fad62d76c1d4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Sun, 28 Mar 2021 04:24:33 +0200 Subject: [PATCH] Fixed possible bug causing InputHandler not to get the correct request-method + simplified Request class. --- src/Pecee/Http/Request.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Pecee/Http/Request.php b/src/Pecee/Http/Request.php index e1d363a..1937b4e 100644 --- a/src/Pecee/Http/Request.php +++ b/src/Pecee/Http/Request.php @@ -23,6 +23,8 @@ class Request public const CONTENT_TYPE_FORM_DATA = 'multipart/form-data'; public const CONTENT_TYPE_X_FORM_ENCODED = 'application/x-www-form-urlencoded'; + public const FORCE_METHOD_KEY = '_method'; + /** * All request-types * @var string[] @@ -127,13 +129,10 @@ class Request $this->setHost($this->getHeader('http-host')); // Check if special IIS header exist, otherwise use default. - $this->setUrl(new Url($this->getFirstHeader(['unencoded-url', 'request-uri',]))); - - $this->setContentType(strtolower($this->getHeader('content-type'))); - - $this->method = strtolower($this->getHeader('request-method')); + $this->setUrl(new Url($this->getFirstHeader(['unencoded-url', 'request-uri']))); + $this->setContentType((string)$this->getHeader('content-type')); + $this->setMethod((string)($_POST[static::FORCE_METHOD_KEY] ?? $this->getHeader('request-method'))); $this->inputHandler = new InputHandler($this); - $this->method = strtolower($this->inputHandler->value('_method', $this->getHeader('request-method'))); } public function isSecure(): bool @@ -324,9 +323,9 @@ class Request protected function setContentType(string $contentType): self { if(strpos($contentType, ';') > 0) { - $this->contentType = substr($contentType, 0, strpos($contentType, ';')); + $this->contentType = strtolower(substr($contentType, 0, strpos($contentType, ';'))); } else { - $this->contentType = $contentType; + $this->contentType = strtolower($contentType); } return $this;