Skip to content

[Framework] Fixed getHeader for returning default value if requested missing #32520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.5-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/internal/Magento/Framework/HTTP/PhpEnvironment/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\HTTP\PhpEnvironment;

use Magento\Framework\App\Filesystem\DirectoryList;
Expand All @@ -25,7 +26,7 @@ class Request extends \Laminas\Http\PhpEnvironment\Request
/**#@+
* Protocols
*/
const SCHEME_HTTP = 'http';
const SCHEME_HTTP = 'http';
const SCHEME_HTTPS = 'https';
/**#@-*/

Expand Down Expand Up @@ -123,7 +124,7 @@ public function __construct(
$uri = UriFactory::factory($uri);
}
if ($uri->isValid()) {
$path = $uri->getPath();
$path = $uri->getPath();
$query = $uri->getQuery();
if (!empty($query)) {
$path .= '?' . $query;
Expand Down Expand Up @@ -302,7 +303,7 @@ public function setAlias($name, $target)
*/
public function getParam($key, $default = null)
{
$key = (string) $key;
$key = (string)$key;
$keyName = (null !== ($alias = $this->getAlias($key))) ? $alias : $key;
if (isset($this->params[$keyName])) {
return $this->params[$keyName];
Expand All @@ -325,7 +326,7 @@ public function getParam($key, $default = null)
*/
public function setParam($key, $value)
{
$key = (string) $key;
$key = (string)$key;
$keyName = (null !== ($alias = $this->getAlias($key))) ? $alias : $key;
if ((null === $value) && isset($this->params[$keyName])) {
unset($this->params[$keyName]);
Expand Down Expand Up @@ -696,7 +697,7 @@ public function getHeader($name, $default = false)
if ($header instanceof HeaderInterface) {
return $header->getFieldValue();
}
return false;
return $header;
}

/**
Expand Down Expand Up @@ -724,7 +725,7 @@ public function getHttpHost($trimPort = true)
/**
* Get the client's IP addres
*
* @param boolean $checkProxy
* @param boolean $checkProxy
* @return string
*/
public function getClientIp($checkProxy = true)
Expand Down Expand Up @@ -795,7 +796,7 @@ public function setRequestUri($requestUri = null)
public function getBaseUrl()
{
$url = urldecode(parent::getBaseUrl());
$url = str_replace(['\\', '/' . DirectoryList::PUB .'/'], '/', $url);
$url = str_replace(['\\', '/' . DirectoryList::PUB . '/'], '/', $url);
return $url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,24 @@ public function testGetCookieNullName()

$this->assertEquals($default, $this->getModel()->getCookie($nullKey, $default));
}

/**
* Get header with default value test
*/
public function testGetHeaderWithDefaultValue()
{
$expectedValue = 'test-value';
$actualValue = $this->getModel()->getHeader('test-header', $expectedValue);
$this->assertEquals($expectedValue, $actualValue);
}

/**
* Get header without default value test
*/
public function testGetHeaderWithoutDefaultValue()
{
$expectedValue = false;
$actualValue = $this->getModel()->getHeader('test-header');
$this->assertEquals($expectedValue, $actualValue);
}
}