Empty response body on some URLs
Closed this issue · 5 comments
Hi there,
When using the Guzzle 6 adapter, the response body of some URLs will be empty, whereas if I just use the Guzzle HTTP client alone, the content comes through just fine.
Before you ask, I'm using the sendRequest()
method, not the sendAsyncRequest()
one, so I don't have to explicitly do Promise
handling.
Steps to reproduce:
Add the following to a composer.json
file and run composer install
:
{
"require": {
"php-http/message": "^1.2",
"php-http/guzzle6-adapter": "^1.1"
}
}
Proof of concept code:
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use Http\Adapter\Guzzle6\Client as HttpClient;
use Http\Message\MessageFactory\GuzzleMessageFactory as MessageFactory;
$sources = [
// Only the Guzzle HTTP client can fetch the contents of this URL
'http://www.artstation.com/artwork.rss',
// Both methods can fetch the contents of this URL
'http://feeds2.feedburner.com/webdesignerdepot',
];
$timeout = 6;
foreach ($sources as $url) {
//
// Guzzle HTTP client
//
$client = new Client([
'timeout' => $timeout,
'connect_timeout' => $timeout,
]);
$response = $client->request('GET', $url);
$guzzle = $response->getBody()->getContents();
//
// Guzzle 6 HTTPlug adapter
//
$client = HttpClient::createWithConfig([
'timeout' => $timeout,
'connect_timeout' => $timeout,
]);
$message = new MessageFactory;
$request = $message->createRequest('GET', $url);
$response = $client->sendRequest($request);
$httplug = $response->getBody()->getContents();
// Uncomment to see the actual contents
// var_dump($guzzle, $httplug);
// Show the fetched URL and the MD5 hash of the content we got
// d41d8cd98f00b204e9800998ecf8427e is the MD5 hash of an empty string
echo $url.':'.PHP_EOL.md5($guzzle).PHP_EOL.md5($httplug).PHP_EOL.PHP_EOL;
}
Edited:
Versions tested:
- PHP 5.5.29 and 7.0.8
php-http/guzzle6-adapter
1.1.1guzzlehttp/guzzle
6.0.0, 6.0.1, 6.0.2, 6.1.0, 6.1.1, 6.2.0, 6.2.1
Try the same but not using
$response->getBody()->getContents();
Instead use:
$response->getBody()->__toString();
No, that's the same... I'll debug this..
I found it!
http://www.artstation.com/artwork.rss redirects to https://www.artstation.com/artwork.rss
By default our adapters/clients does not follow redirects. You could use the RedirectPlugin to solve this issue... or you could update the URL =)