Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* It is now a lot easier to get the effective URL (request #18412)

  * Curl Adapter will properly send a body of PUT request (bug #18421)
  * Prepare release 2.0.0beta3

git-svn-id: http://svn.php.net/repository/pear/packages/HTTP_Request2/trunk@309921 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit f5c5a47939b3b47b0358590db98f37c0d7a011b0 1 parent fbf9741
@sad-spirit sad-spirit authored
View
7 Request2/Adapter/Curl.php
@@ -299,6 +299,9 @@ protected function createCurlHandle()
case HTTP_Request2::METHOD_HEAD:
curl_setopt($ch, CURLOPT_NOBODY, true);
break;
+ case HTTP_Request2::METHOD_PUT:
+ curl_setopt($ch, CURLOPT_UPLOAD, true);
+ break;
default:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->request->getMethod());
}
@@ -494,7 +497,9 @@ protected function callbackWriteHeader($ch, $string)
}
}
if (empty($this->response)) {
- $this->response = new HTTP_Request2_Response($string, false);
+ $this->response = new HTTP_Request2_Response(
+ $string, false, curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)
+ );
} else {
$this->response->parseHeaderLine($string);
if ('' == trim($string)) {
View
4 Request2/Adapter/Socket.php
@@ -925,7 +925,9 @@ protected function readResponse()
$bufferSize = $this->request->getConfig('buffer_size');
do {
- $response = new HTTP_Request2_Response($this->readLine($bufferSize), true);
+ $response = new HTTP_Request2_Response(
+ $this->readLine($bufferSize), true, $this->request->getUrl()
+ );
do {
$headerLine = $this->readLine($bufferSize);
$response->parseHeaderLine($headerLine);
View
29 Request2/Response.php
@@ -96,6 +96,12 @@ class HTTP_Request2_Response
protected $reasonPhrase;
/**
+ * Effective URL (may be different from original request URL in case of redirects)
+ * @var string
+ */
+ protected $effectiveUrl;
+
+ /**
* Associative array of response headers
* @var array
*/
@@ -200,11 +206,12 @@ class HTTP_Request2_Response
/**
* Constructor, parses the response status line
*
- * @param string Response status line (e.g. "HTTP/1.1 200 OK")
- * @param bool Whether body is still encoded by Content-Encoding
+ * @param string Response status line (e.g. "HTTP/1.1 200 OK")
+ * @param bool Whether body is still encoded by Content-Encoding
+ * @param string Effective URL of the response
* @throws HTTP_Request2_MessageException if status line is invalid according to spec
*/
- public function __construct($statusLine, $bodyEncoded = true)
+ public function __construct($statusLine, $bodyEncoded = true, $effectiveUrl = null)
{
if (!preg_match('!^HTTP/(\d\.\d) (\d{3})(?: (.+))?!', $statusLine, $m)) {
throw new HTTP_Request2_MessageException(
@@ -219,7 +226,8 @@ public function __construct($statusLine, $bodyEncoded = true)
} elseif (!empty(self::$phrases[$this->code])) {
$this->reasonPhrase = self::$phrases[$this->code];
}
- $this->bodyEncoded = (bool)$bodyEncoded;
+ $this->bodyEncoded = (bool)$bodyEncoded;
+ $this->effectiveUrl = (string)$effectiveUrl;
}
/**
@@ -338,6 +346,19 @@ public function appendBody($bodyChunk)
}
/**
+ * Returns the effective URL of the response
+ *
+ * This may be different from the request URL if redirects were followed.
+ *
+ * @return string
+ * @link http://pear.php.net/bugs/bug.php?id=18412
+ */
+ public function getEffectiveUrl()
+ {
+ return $this->effectiveUrl;
+ }
+
+ /**
* Returns the status code
* @return integer
*/
View
29 package.xml
@@ -25,9 +25,9 @@ deflate encodings, redirects, monitoring the request progress with Observers...
<email>avb@php.net</email>
<active>yes</active>
</lead>
- <date>2011-03-25</date>
+ <date>2011-04-03</date>
<version>
- <release>2.0.0beta2</release>
+ <release>2.0.0beta3</release>
<api>2.0.0</api>
</version>
<stability>
@@ -36,10 +36,9 @@ deflate encodings, redirects, monitoring the request progress with Observers...
</stability>
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
<notes>
- * Unit tests can now be run under recent PHPUnit versions (3.5+)
- * Public Suffix List updated to current version
- * PHP warning produced by stream_socket_client() in Socket adapter is now
- added to Exception message (bug #18331)
+ * Added getEffectiveUrl() method to Response object, it returns the URL
+ response was received from, possibly after redirects (request #18412)
+ * Curl Adapter didn't send body for PUT requests sometimes (bug #18421)
</notes>
<contents>
<dir baseinstalldir="HTTP" name="/">
@@ -214,6 +213,24 @@ deflate encodings, redirects, monitoring the request progress with Observers...
<changelog>
<release>
<version>
+ <release>2.0.0beta2</release>
+ <api>2.0.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <date>2011-03-25</date>
+ <license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
+ <notes>
+ * Unit tests can now be run under recent PHPUnit versions (3.5+)
+ * Public Suffix List updated to current version
+ * PHP warning produced by stream_socket_client() in Socket adapter is now
+ added to Exception message (bug #18331)
+ </notes>
+ </release>
+ <release>
+ <version>
<release>2.0.0beta1</release>
<api>2.0.0</api>
</version>
View
1  tests/Request2/Adapter/CommonNetworkTest.php
@@ -227,6 +227,7 @@ public function testRedirectsDefault()
$response = $this->request->send();
$this->assertContains('Method=GET', $response->getBody());
$this->assertNotContains('foo', $response->getBody());
+ $this->assertEquals($this->baseUrl . 'redirects.php?redirects=0', $response->getEffectiveUrl());
}
public function testRedirectsStrict()
Please sign in to comment.
Something went wrong with that request. Please try again.