From 71d631680ffc3bb550c954d4267e782581e4928e Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Thu, 24 Jan 2013 18:32:00 -0800 Subject: [PATCH 1/5] Breaking XML attribute parsing into its own method --- .../LocationVisitor/Response/XmlVisitor.php | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php b/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php index 6c0f116c..f024dd6b 100644 --- a/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php +++ b/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php @@ -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']); + } + } + } } From 5e0ff2ef20f839e19d1eeb298f90ba3598784444 Mon Sep 17 00:00:00 2001 From: Ben Parker Date: Fri, 25 Jan 2013 22:40:55 +0000 Subject: [PATCH 2/5] Changes value of CURLOPT_SSL_VERIFYHOST set in Http Client 1 as a value for CURLOPT_SSL_VERIFYHOST is deprecated in libcurl 7.28.1, recommended value is now 2 --- src/Guzzle/Http/Client.php | 2 +- tests/Guzzle/Tests/Http/ClientTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Guzzle/Http/Client.php b/src/Guzzle/Http/Client.php index 089b3ab3..38b40e54 100644 --- a/src/Guzzle/Http/Client.php +++ b/src/Guzzle/Http/Client.php @@ -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) { diff --git a/tests/Guzzle/Tests/Http/ClientTest.php b/tests/Guzzle/Tests/Http/ClientTest.php index dfb18f7e..a1948408 100644 --- a/tests/Guzzle/Tests/Http/ClientTest.php +++ b/tests/Guzzle/Tests/Http/ClientTest.php @@ -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]); } /** From 62333959189918cd651b5e1726e1d1960b71844d Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Sat, 26 Jan 2013 00:20:43 -0800 Subject: [PATCH 3/5] Fixing redirect response chaining. Closes #223 --- src/Guzzle/Http/RedirectPlugin.php | 4 ++- .../Guzzle/Tests/Http/RedirectPluginTest.php | 25 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Guzzle/Http/RedirectPlugin.php b/src/Guzzle/Http/RedirectPlugin.php index fb80f83b..de481767 100644 --- a/src/Guzzle/Http/RedirectPlugin.php +++ b/src/Guzzle/Http/RedirectPlugin.php @@ -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); + } } /** diff --git a/tests/Guzzle/Tests/Http/RedirectPluginTest.php b/tests/Guzzle/Tests/Http/RedirectPluginTest.php index 2d2a9356..c7cdb8ea 100644 --- a/tests/Guzzle/Tests/Http/RedirectPluginTest.php +++ b/tests/Guzzle/Tests/Http/RedirectPluginTest.php @@ -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() From 7901ea7d27373d0cc85eac6f6694e4c2ced90a26 Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Sun, 27 Jan 2013 16:07:40 -0800 Subject: [PATCH 4/5] Tagging 3.1.2 release --- CHANGELOG.md | 10 ++++++++++ src/Guzzle/Common/Version.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index affe355d..0edf39de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) ------------------ diff --git a/src/Guzzle/Common/Version.php b/src/Guzzle/Common/Version.php index 55ff36ea..9b8a827c 100644 --- a/src/Guzzle/Common/Version.php +++ b/src/Guzzle/Common/Version.php @@ -7,5 +7,5 @@ namespace Guzzle\Common; */ class Version { - const VERSION = '3.1.1'; + const VERSION = '3.1.2'; } From 30a33083e71cb64e422b810b748414b245a6d640 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: Mon, 28 Jan 2013 21:12:58 +0100 Subject: [PATCH 5/5] Remove request and response object from message string --- src/Guzzle/Http/Exception/BadResponseException.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Guzzle/Http/Exception/BadResponseException.php b/src/Guzzle/Http/Exception/BadResponseException.php index e3400950..e3a6705f 100644 --- a/src/Guzzle/Http/Exception/BadResponseException.php +++ b/src/Guzzle/Http/Exception/BadResponseException.php @@ -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);