1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-25 02:22:57 +01:00

Merge remote-tracking branch 'origin/master' into refactor-url

This commit is contained in:
David Abdemoulaie 2013-01-30 17:17:57 -06:00
commit 3942ab7eff
8 changed files with 55 additions and 18 deletions

View File

@ -1,6 +1,16 @@
CHANGELOG
=========
3.1.2 (2013-01-27)
------------------
* Refactored how operation responses are parsed. Visitors now include a before() method responsible for parsing the
response body. For example, the XmlVisitor now parses the XML response into an array in the before() method.
* Fixed an issue where cURL would not automatically decompress responses when the Accept-Encoding header was sent
* CURLOPT_SSL_VERIFYHOST is never set to 1 because it is deprecated (see 5e0ff2ef20f839e19d1eeb298f90ba3598784444)
* Fixed a bug where redirect responses were not chained correctly using getPreviousResponse()
* Setting default headers on a client after setting the user-agent will not erase the user-agent setting
3.1.1 (2013-01-20)
------------------

View File

@ -7,5 +7,5 @@ namespace Guzzle\Common;
*/
class Version
{
const VERSION = '3.1.1';
const VERSION = '3.1.2';
}

View File

@ -138,7 +138,7 @@ class Client extends AbstractHasDispatcher implements ClientInterface
} elseif ($certificateAuthority === false) {
unset($opts[CURLOPT_CAINFO]);
$opts[CURLOPT_SSL_VERIFYPEER] = false;
$opts[CURLOPT_SSL_VERIFYHOST] = 1;
$opts[CURLOPT_SSL_VERIFYHOST] = 2;
} elseif ($verifyPeer !== true && $verifyPeer !== false && $verifyPeer !== 1 && $verifyPeer !== 0) {
throw new InvalidArgumentException('verifyPeer must be 1, 0 or boolean');
} elseif ($verifyHost !== 0 && $verifyHost !== 1 && $verifyHost !== 2) {

View File

@ -41,8 +41,6 @@ class BadResponseException extends RequestException
'[status code] ' . $response->getStatusCode(),
'[reason phrase] ' . $response->getReasonPhrase(),
'[url] ' . $request->getUrl(),
'[request] ' . (string) $request,
'[response] ' . (string) $response
));
$e = new $class($message);

View File

@ -78,8 +78,10 @@ class RedirectPlugin implements EventSubscriberInterface
// Send the redirect request and hijack the response of the original request
$redirectResponse = $redirectRequest->send();
$redirectResponse->setPreviousResponse($event['response']);
$request->setResponse($redirectResponse);
if (!$redirectResponse->getPreviousResponse()) {
$redirectResponse->setPreviousResponse($response);
}
}
/**

View File

@ -117,13 +117,7 @@ class XmlVisitor extends AbstractResponseVisitor
$name = $property->getName();
$sentAs = $property->getWireName();
if ($property->getData('xmlAttribute')) {
if (isset($value['@attributes'][$sentAs])) {
$value[$name] = $value['@attributes'][$sentAs];
unset($value['@attributes'][$sentAs]);
if (empty($value['@attributes'])) {
unset($value['@attributes']);
}
}
$this->processXmlAttribute($property, $value);
} elseif (isset($value[$sentAs])) {
$this->recursiveProcess($property, $value[$sentAs]);
if ($name != $sentAs) {
@ -137,4 +131,22 @@ class XmlVisitor extends AbstractResponseVisitor
}
}
}
/**
* Process an XML attribute property
*
* @param Parameter $property Property to process
* @param array $value Value to process and update
*/
protected function processXmlAttribute(Parameter $property, array &$value)
{
$sentAs = $property->getWireName();
if (isset($value['@attributes'][$sentAs])) {
$value[$property->getName()] = $value['@attributes'][$sentAs];
unset($value['@attributes'][$sentAs]);
if (empty($value['@attributes'])) {
unset($value['@attributes']);
}
}
}
}

View File

@ -228,7 +228,7 @@ class ClientTest extends \Guzzle\Tests\GuzzleTestCase
$options = $client->getConfig('curl.options');
$this->assertArrayNotHasKey(CURLOPT_CAINFO, $options);
$this->assertSame(false, $options[CURLOPT_SSL_VERIFYPEER]);
$this->assertSame(1, $options[CURLOPT_SSL_VERIFYHOST]);
$this->assertSame(2, $options[CURLOPT_SSL_VERIFYHOST]);
}
/**

View File

@ -17,8 +17,8 @@ class RedirectPluginTest extends \Guzzle\Tests\GuzzleTestCase
// Flush the server and queue up a redirect followed by a successful response
$this->getServer()->flush();
$this->getServer()->enqueue(array(
"HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
"HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect\r\nContent-Length: 0\r\n\r\n",
"HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n",
"HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect2\r\nContent-Length: 0\r\n\r\n",
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
));
@ -33,17 +33,32 @@ class RedirectPluginTest extends \Guzzle\Tests\GuzzleTestCase
// Ensure that two requests were sent
$this->assertEquals('/foo', $requests[0]->getResource());
$this->assertEquals('GET', $requests[0]->getMethod());
$this->assertEquals('/redirect', $requests[1]->getResource());
$this->assertEquals('/redirect1', $requests[1]->getResource());
$this->assertEquals('GET', $requests[1]->getMethod());
$this->assertEquals('/redirect', $requests[2]->getResource());
$this->assertEquals('/redirect2', $requests[2]->getResource());
$this->assertEquals('GET', $requests[2]->getMethod());
// Ensure that the previous response was set correctly
$this->assertEquals(301, $response->getPreviousResponse()->getStatusCode());
$this->assertEquals('/redirect', (string) $response->getPreviousResponse()->getHeader('Location'));
$this->assertEquals('/redirect2', (string) $response->getPreviousResponse()->getHeader('Location'));
// Ensure that the redirect count was incremented
$this->assertEquals(2, $request->getParams()->get(RedirectPlugin::REDIRECT_COUNT));
$c = 0;
$r = $response->getPreviousResponse();
while ($r) {
if ($c == 0) {
$this->assertEquals('/redirect2', $r->getLocation());
} else {
$this->assertEquals('/redirect1', $r->getLocation());
}
$c++;
$r = $r->getPreviousResponse();
}
$this->assertEquals(2, $c);
}
public function testCanLimitNumberOfRedirects()