Skip to content

Commit 35d07a3

Browse files
committed
Fixed handling of response headers
1 parent 7c59d8c commit 35d07a3

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎src/WpHandler.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function handle(RequestInterface $request): ResponseInterface
6161
$code = (int) wp_remote_retrieve_response_code($responseData);
6262
$reason = wp_remote_retrieve_response_message($responseData);
6363
$headers = wp_remote_retrieve_headers($responseData);
64+
$headers = is_array($headers) ? $headers : iterator_to_array($headers);
6465
$body = wp_remote_retrieve_body($responseData);
6566

6667
return new Response($code, $headers, $body, $httpVer, $reason);

‎tests/WpHandlerTest.php‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@
1010
use RebelCode\Psr7\Uri;
1111
use RebelCode\WordPress\Http\HandlerInterface;
1212
use RebelCode\WordPress\Http\WpHandler;
13+
use Requests_Utility_CaseInsensitiveDictionary;
1314
use WP_Mock;
1415

1516
/** @covers \RebelCode\WordPress\Http\WpHandler */
1617
class WpHandlerTest extends TestCase
1718
{
19+
public static function setUpBeforeClass()
20+
{
21+
if (!class_exists('Requests_Utility_CaseInsensitiveDictionary')) {
22+
require WORDPRESS_DIR . '/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php';
23+
}
24+
25+
if (!class_exists('Requests_Exception')) {
26+
require WORDPRESS_DIR . '/wp-includes/Requests/Exception.php';
27+
}
28+
}
29+
1830
protected function setUp(): void
1931
{
2032
WP_Mock::setUp();
@@ -55,10 +67,10 @@ public function testHandle()
5567
{
5668
$statusCode = 201;
5769
$statusReason = 'Created';
58-
$responseHeaders = [
70+
$responseHeaders = new Requests_Utility_CaseInsensitiveDictionary([
5971
'Sam' => 'Eggs, Ham',
6072
'Cat' => 'Hat',
61-
];
73+
]);
6274
$responseBody = 'Some response body content here';
6375

6476
$responseData = [

‎tests/bootstrap.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3-
require_once __DIR__ . '/../vendor/autoload.php';
3+
const VENDOR_DIR = __DIR__ . '/../vendor';
4+
const WORDPRESS_DIR = VENDOR_DIR . '/johnpbloch/wordpress-core';
5+
6+
require_once VENDOR_DIR . '/autoload.php';
47

58
WP_Mock::bootstrap();

0 commit comments

Comments
 (0)