]> source.dussan.org Git - nextcloud-server.git/commitdiff
Don't try to parse empty body if there is no body 4147/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 29 Mar 2017 13:09:45 +0000 (15:09 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Tue, 4 Apr 2017 06:22:33 +0000 (08:22 +0200)
Fixes #3890

If we do a put request without a body the current code still tries to
read the body. This patch makes sure that we do not try to read the body
if the content length is 0.

See RFC 2616 Section 4.3

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
lib/private/AppFramework/Http/Request.php
tests/lib/AppFramework/Http/RequestTest.php

index fd43d468568da8e04da15ceff99b64509da7943a..3f1e6fd951acc8b02e3f8c4d1c97674c758a2953 100644 (file)
@@ -401,6 +401,8 @@ class Request implements \ArrayAccess, \Countable, IRequest {
        protected function getContent() {
                // If the content can't be parsed into an array then return a stream resource.
                if ($this->method === 'PUT'
+                       && $this->getHeader('Content-Length') !== 0
+                       && $this->getHeader('Content-Length') !== null
                        && strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false
                        && strpos($this->getHeader('Content-Type'), 'application/json') === false
                ) {
index cc4bbee2d8d3c918dcd291985ff34df2ab32b520..f80bffcb4804fa05e92a63672cdb97a2b0b91268 100644 (file)
@@ -305,7 +305,10 @@ class RequestTest extends \Test\TestCase {
                $vars = array(
                        'put' => $data,
                        'method' => 'PUT',
-                       'server' => array('CONTENT_TYPE' => 'image/png'),
+                       'server' => [
+                               'CONTENT_TYPE' => 'image/png',
+                               'CONTENT_LENGTH' => strlen($data)
+                       ],
                );
 
                $request = new Request(