Skip to content

Commit

Permalink
[5.5] Fix unsetting http query parameters when fetching request by HE…
Browse files Browse the repository at this point in the history
…AD (#24076)

* fix request method to use $_GET variables when HEAD

* fix coding style of http request
  • Loading branch information
Lynn Lin authored and taylorotwell committed May 2, 2018
1 parent 84abd78 commit ac963a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Illuminate/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ protected function getInputSource()
return $this->json();
}

return $this->getRealMethod() == 'GET' ? $this->query : $this->request;
return in_array($this->getRealMethod(), ['GET', 'HEAD']) ? $this->query : $this->request;
}

/**
Expand All @@ -358,8 +358,12 @@ public static function createFromBase(SymfonyRequest $request)
$content = $request->content;

$request = (new static)->duplicate(
$request->query->all(), $request->request->all(), $request->attributes->all(),
$request->cookies->all(), $request->files->all(), $request->server->all()
$request->query->all(),
$request->request->all(),
$request->attributes->all(),
$request->cookies->all(),
$request->files->all(),
$request->server->all()
);

$request->content = $content;
Expand Down Expand Up @@ -472,7 +476,8 @@ public function fingerprint()
}

return sha1(implode('|', array_merge(
$route->methods(), [$route->getDomain(), $route->uri(), $this->ip()]
$route->methods(),
[$route->getDomain(), $route->uri(), $this->ip()]
)));
}

Expand Down Expand Up @@ -558,7 +563,8 @@ public function toArray()
public function offsetExists($offset)
{
return array_key_exists(
$offset, $this->all() + $this->route()->parameters()
$offset,
$this->all() + $this->route()->parameters()
);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ public function testReplaceMethod()
$this->assertEquals('Dayle', $request->input('buddy'));
}

public function testOffsetUnsetMethod()
{
$request = Request::create('/', 'HEAD', ['name' => 'Taylor']);
$request->offsetUnset('name');
$this->assertNull($request->input('name'));
}

public function testHeaderMethod()
{
$request = Request::create('/', 'GET', [], [], [], ['HTTP_DO_THIS' => 'foo']);
Expand Down

0 comments on commit ac963a0

Please sign in to comment.