Fix IHTTPResult::getHeader/s()

- Split functionality "getHeader()" and "getHeaders()" analog to IMessageInterface::getHeader/s()
- Fix functionality at various places - Adapt CurlResultTest
This commit is contained in:
Philipp
2021-08-20 19:48:14 +02:00
parent a60ca4a1cf
commit dee1899628
10 changed files with 89 additions and 22 deletions
+12 -6
View File
@@ -242,23 +242,29 @@ class CurlResult implements IHTTPResult
}
/** {@inheritDoc} */
public function getHeader(string $field = '')
public function getHeader($header)
{
if (empty($field)) {
return $this->header;
if (empty($header)) {
return '';
}
$field = strtolower(trim($field));
$header = strtolower(trim($header));
$headers = $this->getHeaderArray();
if (isset($headers[$field])) {
return $headers[$field];
if (isset($headers[$header])) {
return $headers[$header];
}
return '';
}
/** {@inheritDoc} */
public function getHeaders()
{
return $this->getHeaderArray();
}
/** {@inheritDoc} */
public function inHeader(string $field)
{
+1 -2
View File
@@ -493,8 +493,7 @@ class HTTPRequest implements IHTTPRequest
'timeout' => $timeout,
'accept_content' => $accept_content,
'cookiejar' => $cookiejar
],
$redirects
]
);
}
+19 -3
View File
@@ -2,6 +2,8 @@
namespace Friendica\Network;
use Psr\Http\Message\MessageInterface;
/**
* Temporary class to map Friendica used variables based on PSR-7 HTTPResponse
*/
@@ -23,15 +25,25 @@ interface IHTTPResult
/**
* Returns the headers
* @see MessageInterface::getHeader()
*
* @param string $field optional header field. Return all fields if empty
* @param string $header optional header field. Return all fields if empty
*
* @return string the headers or the specified content of the header variable
*/
public function getHeader(string $field = '');
public function getHeader($header);
/**
* Returns all headers
* @see MessageInterface::getHeaders()
*
* @return string[][]
*/
public function getHeaders();
/**
* Check if a specified header exists
* @see MessageInterface::hasHeader()
*
* @param string $field header field
*
@@ -41,8 +53,10 @@ interface IHTTPResult
/**
* Returns the headers as an associated array
* @see MessageInterface::getHeaders()
* @deprecated
*
* @return array associated header array
* @return string[][] associated header array
*/
public function getHeaderArray();
@@ -62,6 +76,8 @@ interface IHTTPResult
public function getRedirectUrl();
/**
* @see MessageInterface::getBody()
*
* @return string
*/
public function getBody();