* The utterly misunderstood HttpResponse class has been reimplemented as http\Env\Response inheriting http\Message.
* Currently, there's only one Exception class left, http\Exception.
* Errors triggered by the extension can be configured statically by http\Object::$defaultErrorHandling or inherited http\Object->errorHandling.
-* The request ecosystem has been modularized to support different libraries, though for the moment only libcurl is supported;
- Nevertheless, you have to use the http\Request\Factory to create your request/pool/datashare objects.
+* The request ecosystem has been modularized to support different libraries, though for the moment only libcurl is supported.
]]></description>
<lead>
<name>Michael Wallner</name>
<email>mike@php.net</email>
<active>yes</active>
</lead>
- <date>2012-03-23</date>
+ <date>2012-03-30</date>
<version>
- <release>2.0.0dev9</release>
+ <release>2.0.0dev10</release>
<api>2.0.0</api>
</version>
<stability>
</stability>
<license>BSD, revised</license>
<notes><![CDATA[
-+
++ This release contains the http\Request to http\Client refactoring triggered by Benjamin Eberlei. Many thanks.
]]></notes>
<contents>
<dir name="/">
STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_message_t *msg)
{
+ size_t body_size;
php_http_curl_client_t *curl = h->ctx;
php_http_curl_client_storage_t *storage = get_storage(curl->handle);
TSRMLS_FETCH_FROM_CTX(h->ts);
}
/* attach request body */
- {
+ if ((body_size = php_http_message_body_size(&msg->body))) {
/* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
* specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
* Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
* same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
* does not allow a request body.
*/
- size_t body_size = php_http_message_body_size(&msg->body);
-
+ php_stream_rewind(php_http_message_body_stream(&msg->body));
curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, &msg->body);
curl_easy_setopt(curl->handle, CURLOPT_READDATA, &msg->body);
curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
protected $r;
function setUp() {
- $this->r = (new http\Request\Factory)->createRequest();
+ $this->r = (new http\Client\Factory)->createClient();
$this->r->setOptions(
array(
"connecttimeout" => 30,
}
function testClone() {
- $this->r->setUrl("http://dev.iworks.at/ext-http/.print_request.php");
$c = clone $this->r;
- $c->setUrl("http://dev.iworks.at/ext-http/.print_headers.php");
- $this->assertNotEquals($this->r->send(), $c->send());
+ $this->assertNotSame($this->r, $c);
}
function testObserver() {
}
)
);
- $this->r->setUrl("http://dev.iworks.at/ext-http/")->send();
+ $this->r->setRequest(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/"))->send(null);
$this->assertRegexp("/(\.-)+/", $this->r->pi);
$this->assertCount(3, $this->r->getObservers());
}
function testCookies() {
- $this->r->setUrl("http://dev.iworks.at/ext-http/.cookie.php")->send();
+ $this->r->setRequest(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie.php"))->send(null);
$this->assertNotContains("Cookie", (string) $this->r->getRequestMessage());
- $this->r->send();
+ $this->r->send(null);
$this->assertNotContains("Cookie", (string) $this->r->getRequestMessage());
- $this->r->enableCookies()->send();
+ $this->r->enableCookies()->send(null);
$this->assertNotContains("Cookie", (string) $this->r->getRequestMessage());
- $this->r->send();
+ $this->r->send(null);
$this->assertContains("Cookie", (string) $this->r->getRequestMessage());
- $this->assertCount(2, $this->r->getResponseCookies());
+ $this->assertCount(2, $this->r->getResponseMessage()->getCookies());
}
function testResetCookies() {
- $this->r->setUrl("http://dev.iworks.at/ext-http/.cookie.php");
+ $this->r->setRequest(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie.php"));
$this->r->enableCookies();
- $this->r->send();
+ $this->r->send(null);
$f = function ($a) { return $a->getCookies(); };
- $c = array_map($f, $this->r->getResponseCookies());
+ $c = array_map($f, $this->r->getResponseMessage()->getCookies());
- $this->r->send();
- $this->assertEquals($c, array_map($f, $this->r->getResponseCookies()));
+ $this->r->send(null);
+ $this->assertEquals($c, array_map($f, $this->r->getResponseMessage()->getCookies()));
$this->r->resetCookies();
- $this->r->send();
- $this->assertNotEquals($c, array_map($f, $this->r->getResponseCookies()));
+ $this->r->send(null);
+ $this->assertNotEquals($c, array_map($f, $this->r->getResponseMessage()->getCookies()));
}
function testHistory() {
$body = new http\Message\Body;
$body->append("foobar");
- $this->r->setBody($body);
- $this->r->recordHistory = true;
+ $request = new http\Client\Request;
+ $request->setBody($body);
+ $request->setRequestMethod("POST");
+ $request->setRequestUrl("http://dev.iworks.at/ext-http/.print_request.php");
- $this->r->setMethod("POST");
- $this->r->setUrl("http://dev.iworks.at/ext-http/.print_request.php");
+ $this->r->recordHistory = true;
+ $this->r->send($request);
- $this->r->send();
$this->assertStringMatchesFormat(<<<HTTP
POST /ext-http/.print_request.php HTTP/1.1
User-Agent: %s
, str_replace("\r", "", $this->r->getHistory()->toString(true))
);
- $this->r->send();
+
+ $this->r->send($request);
+
$this->assertStringMatchesFormat(<<<HTTP
POST /ext-http/.print_request.php HTTP/1.1
User-Agent: %s
--SKIPIF--
<?php
include "skipif.inc";
-in_array("curl", http\Request\Factory::getAvailableDrivers()) or die ("skip CURL support missing");
+in_array("curl", http\Client\Factory::getAvailableDrivers()) or die ("skip CURL support missing");
?>
--FILE--
<?php
echo "Test\n";
-class MyRequest extends http\Request {}
-class MyPool extends http\Request\Pool {}
-class MyShare extends http\Request\DataShare {}
+class MyClient extends http\Curl\Client {}
+class MyPool extends http\Curl\Client\Pool {}
+class MyShare extends http\Curl\Client\DataShare {}
-class MyFactory extends http\Request\Factory {
+class MyFactory extends http\Client\Factory {
protected $driver = "curl";
protected $persistentHandleId = "My";
- protected $requestClass = "MyRequest";
- protected $requestPoolClass = "MyPool";
- protected $requestDataShareClass = "MyShare";
+ protected $clientClass = "MyClient";
+ protected $clientPoolClass = "MyPool";
+ protected $clientDataShareClass = "MyShare";
protected $dummy = "foo";
}
$f = new MyFactory(array("driver" => "curl"));
-$r = $f->createRequest();
+$r = $f->createClient();
$p = $f->createPool();
$s = $f->createDataShare();
$f->getDriver()
);
-foreach (array("Request", "Pool", "DataShare") as $type) {
+foreach (array("Client", "Pool", "DataShare") as $type) {
try {
- var_dump((new http\Request\Factory(array("driver" => "nonexistant")))->{"create$type"}());
+ var_dump((new http\Client\Factory(array("driver" => "nonexistant")))->{"create$type"}());
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
[0]=>
string(9) "MyFactory"
[1]=>
- string(9) "MyRequest"
+ string(8) "MyClient"
[2]=>
string(6) "MyPool"
[3]=>
string(7) "MyShare"
}
string(4) "curl"
-requests are not supported by this driver
+clients are not supported by this driver
pools are not supported by this driver
datashares are not supported by this driver
Done
echo "Done\n";
--EXPECTF--
Test
-string(3) "0.0"
+string(3) "1.1"
bool(true)
array(0) {
}
<?php include "skipif.inc"; ?>
--FILE--
<?php
-(new http\Request\Factory(array("persistentHandleId" => "foo")))
- ->createRequest("http://dev.iworks.at")
+(new http\Client\Factory(array("persistentHandleId" => "foo")))
+ ->createClient()->setRequest(new http\Client\Request("GET", "http://dev.iworks.at"))
->setOptions(array("connecttimeout"=> 90, "timeout" =>300))
- ->send();
-$r = (new http\Request\Factory(array("persistentHandleId" => "bar")))
- ->createRequest("http://dev.iworks.at")
+ ->send(null);
+$r = (new http\Client\Factory(array("persistentHandleId" => "bar")))
+ ->createClient()->setRequest(new http\Client\Request("GET", "http://dev.iworks.at"))
->setOptions(array("connecttimeout"=> 90, "timeout" =>300));
var_dump(http\Env::statPersistentHandles());
http\Env::cleanPersistentHandles();
var_dump(http\Env::statPersistentHandles());
-$r->send();
+$r->send(null);
var_dump(http\Env::statPersistentHandles());
?>
DONE
--EXPECTF--
object(stdClass)#%d (3) {
- ["http_request_datashare.curl"]=>
- array(0) {
- }
- ["http_request_pool.curl"]=>
- array(0) {
- }
- ["http_request.curl"]=>
+ ["http_client.curl"]=>
array(2) {
["foo"]=>
array(2) {
int(0)
}
}
-}
-object(stdClass)#%d (3) {
- ["http_request_datashare.curl"]=>
+ ["http_client_pool.curl"]=>
array(0) {
}
- ["http_request_pool.curl"]=>
+ ["http_client_datashare.curl"]=>
array(0) {
}
- ["http_request.curl"]=>
+}
+object(stdClass)#%d (3) {
+ ["http_client.curl"]=>
array(1) {
["bar"]=>
array(2) {
int(0)
}
}
-}
-object(stdClass)#%d (3) {
- ["http_request_datashare.curl"]=>
+ ["http_client_pool.curl"]=>
array(0) {
}
- ["http_request_pool.curl"]=>
+ ["http_client_datashare.curl"]=>
array(0) {
}
- ["http_request.curl"]=>
+}
+object(stdClass)#%d (3) {
+ ["http_client.curl"]=>
array(1) {
["bar"]=>
array(2) {
int(0)
}
}
+ ["http_client_pool.curl"]=>
+ array(0) {
+ }
+ ["http_client_datashare.curl"]=>
+ array(0) {
+ }
}
DONE
--FILE--
<?php
-use http\request\Factory as HttpRequestFactory;
-use http\request\Pool as HttpRequestPool;
-use http\Exception as HttpRequestException;
-use http\Exception as HttpSocketException;
-
echo "-TEST\n";
set_time_limit(0);
ini_set('error_reporting', E_ALL);
ini_set('html_errors', 0);
-class Pool extends HttpRequestPool
+class Pool extends \http\Curl\Client\Pool
{
private $all;
private $rem;
foreach ($now as $url => $file) {
$this->attach(
- $this->factory->createRequest(
- $url,
- "GET",
+ $this->factory->createClient(
array(
'redirect' => 5,
'compress' => GZIP,
'connecttimeout' => TOUT,
'lastmodified' => is_file($file)?filemtime($file):0
)
- )
+ )->setRequest(new http\Client\Request("GET", $url))
);
}
while ($this->once()) {
if (!$this->wait()) {
- throw new HttpSocketException;
+ throw new http\Exception;
}
}
}
{
try {
$rc = parent::once();
- } catch (HttpRequestException $x) {
+ } catch (http\Exception $x) {
// a request may have thrown an exception,
// but it is still save to continue
echo $x->getMessage(), "\n";
}
- foreach ($this->getFinishedRequests() as $r) {
+ foreach ($this->getFinished() as $r) {
$this->detach($r);
- $u = $r->getUrl();
- $c = $r->getResponseCode();
+ $u = $r->getRequest()->getRequestUrl();
+ $c = $r->getResponseMessage()->getResponseCode();
try {
- $b = $r->getResponseBody();
+ $b = $r->getResponseMessage()->getBody();
} catch (\Exception $e) {
echo $e->getMessage(), "\n";
$b = "";
if ($a = each($this->rem)) {
list($url, $file) = $a;
$this->attach(
- $this->factory->createRequest(
- $url,
- "GET",
+ $this->factory->createClient(
array(
'redirect' => 5,
'compress' => GZIP,
'connecttimeout' => TOUT,
'lastmodified' => is_file($file)?filemtime($file):0
)
- )
+ )->setRequest(new http\Client\Request("GET", $url))
);
}
}
chdir(__DIR__);
$time = microtime(true);
-$factory = new HttpRequestFactory(array("driver" => "curl", "requestPoolClass" => "Pool"));
+$factory = new http\Client\Factory(array("driver" => "curl", "clientPoolClass" => "Pool"));
$factory->createPool()->run($factory);
printf("Elapsed: %0.3fs\n", microtime(true)-$time);