10 $client->addCurlSetting(CURLOPT_POSTREDIR, 0);
12 $request =
new Request(
'GET',
'http://example.org/', [
'X-Foo' =>
'bar']);
15 CURLOPT_RETURNTRANSFER =>
true,
16 CURLOPT_HEADER =>
true,
17 CURLOPT_POSTREDIR => 0,
18 CURLOPT_HTTPHEADER => [
'X-Foo: bar'],
19 CURLOPT_NOBODY =>
false,
20 CURLOPT_URL =>
'http://example.org/',
21 CURLOPT_CUSTOMREQUEST =>
'GET',
22 CURLOPT_POSTFIELDS =>
'',
24 CURLOPT_USERAGENT =>
'sabre-http/' .
Version::VERSION .
' (http://sabre.io/)',
29 if (defined(
'HHVM_VERSION') ===
false) {
30 $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
31 $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
35 $this->assertEquals($settings,
$client->createCurlSettingsArray(
$request));
42 $request =
new Request(
'HEAD',
'http://example.org/', [
'X-Foo' =>
'bar']);
46 CURLOPT_RETURNTRANSFER =>
true,
47 CURLOPT_HEADER =>
true,
48 CURLOPT_NOBODY =>
true,
49 CURLOPT_CUSTOMREQUEST =>
'HEAD',
50 CURLOPT_HTTPHEADER => [
'X-Foo: bar'],
51 CURLOPT_URL =>
'http://example.org/',
52 CURLOPT_POSTFIELDS =>
'',
54 CURLOPT_USERAGENT =>
'sabre-http/' .
Version::VERSION .
' (http://sabre.io/)',
59 if (defined(
'HHVM_VERSION') ===
false) {
60 $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
61 $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
64 $this->assertEquals($settings,
$client->createCurlSettingsArray(
$request));
71 $request =
new Request(
'HEAD',
'http://example.org/', [
'X-Foo' =>
'bar']);
79 $request =
new Request(
'GET',
'http://example.org/', [
'X-Foo' =>
'bar']);
82 CURLOPT_CUSTOMREQUEST =>
'GET',
83 CURLOPT_RETURNTRANSFER =>
true,
84 CURLOPT_HEADER =>
true,
85 CURLOPT_HTTPHEADER => [
'X-Foo: bar'],
86 CURLOPT_NOBODY =>
false,
87 CURLOPT_URL =>
'http://example.org/',
88 CURLOPT_POSTFIELDS =>
'',
90 CURLOPT_USERAGENT =>
'sabre-http/' .
Version::VERSION .
' (http://sabre.io/)',
95 if (defined(
'HHVM_VERSION') ===
false) {
96 $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
97 $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
100 $this->assertEquals($settings,
$client->createCurlSettingsArray(
$request));
108 $h =
fopen(
'php://memory',
'r+');
113 CURLOPT_RETURNTRANSFER =>
true,
114 CURLOPT_HEADER =>
true,
116 CURLOPT_INFILE =>
$h,
117 CURLOPT_NOBODY =>
false,
118 CURLOPT_CUSTOMREQUEST =>
'PUT',
119 CURLOPT_HTTPHEADER => [
'X-Foo: bar'],
120 CURLOPT_URL =>
'http://example.org/',
121 CURLOPT_USERAGENT =>
'sabre-http/' .
Version::VERSION .
' (http://sabre.io/)',
126 if (defined(
'HHVM_VERSION') ===
false) {
127 $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
128 $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
131 $this->assertEquals($settings,
$client->createCurlSettingsArray(
$request));
138 $request =
new Request(
'PUT',
'http://example.org/', [
'X-Foo' =>
'bar'],
'boo');
141 CURLOPT_RETURNTRANSFER =>
true,
142 CURLOPT_HEADER =>
true,
143 CURLOPT_NOBODY =>
false,
144 CURLOPT_POSTFIELDS =>
'boo',
145 CURLOPT_CUSTOMREQUEST =>
'PUT',
146 CURLOPT_HTTPHEADER => [
'X-Foo: bar'],
147 CURLOPT_URL =>
'http://example.org/',
148 CURLOPT_USERAGENT =>
'sabre-http/' .
Version::VERSION .
' (http://sabre.io/)',
153 if (defined(
'HHVM_VERSION') ===
false) {
154 $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
155 $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
158 $this->assertEquals($settings,
$client->createCurlSettingsArray(
$request));
173 $this->assertEquals(200,
$response->getStatus());
186 $client->on(
'exception',
function() use (&$called) {
192 $this->fail(
'send() should have thrown an exception');
196 $this->assertTrue($called);
209 $client->on(
'error',
function() use (&$called) {
212 $client->on(
'error:404',
function() use (&$called) {
217 $this->assertEquals(2, $called);
245 $this->assertEquals(3, $called);
246 $this->assertEquals(2, $errorCalled);
247 $this->assertEquals(200,
$response->getStatus());
254 $client->setThrowExceptions(
true);
263 $this->fail(
'An exception should have been thrown');
266 $this->assertInstanceOf(
'Sabre\HTTP\Response', $e->
getResponse());
274 $client->on(
'curlStuff',
function(&$return) {
287 $body =
"HTTP/1.1 200 OK\r\nHeader1:Val1\r\n\r\nFoo";
291 $this->assertEquals(200,
$result[
'http_code']);
292 $this->assertEquals(200,
$result[
'response']->getStatus());
301 $client->on(
'curlStuff',
function(&$return) {
311 $body =
"HTTP/1.1 200 OK\r\nHeader1:Val1\r\n\r\nFoo";
315 $this->assertEquals(1,
$result[
'curl_errno']);
316 $this->assertEquals(
'Curl error',
$result[
'curl_errmsg']);
324 $client->on(
'curlExec',
function(&$return) {
326 $return =
"HTTP/1.1 200 OK\r\nHeader1:Val1\r\n\r\nFoo";
329 $client->on(
'curlStuff',
function(&$return) {
342 $this->assertEquals(200,
$response->getStatus());
343 $this->assertEquals([
'Header1' => [
'Val1']],
$response->getHeaders());
344 $this->assertEquals(
'Foo',
$response->getBodyAsString());
352 $client->on(
'curlExec',
function(&$return) {
357 $client->on(
'curlStuff',
function(&$return) {
369 $this->fail(
'This should have thrown an exception');
371 $this->assertEquals(1, $e->getCode());
372 $this->assertEquals(
'Curl error', $e->getMessage());
381 protected $persistedSettings = [];
395 $settings = parent::createCurlSettingsArray($request);
396 $settings = $settings + $this->persistedSettings;
397 $this->persistedSettings = $settings;
406 return parent::parseCurlResult(
$response, $curlHandle);
423 return parent::doRequest($request);
441 $this->
emit(
'curlStuff', [&$return]);
444 if (is_null($return)) {
445 return parent::curlStuff($curlHandle);
463 $this->
emit(
'curlExec', [&$return]);
466 if (is_null($return)) {
467 return parent::curlExec($curlHandle);
This exception may be emitted by the HTTP class, in case there was a problem emitting the request...
The RequestInterface represents a HTTP request.
getHttpStatus()
The http status code for the error.
createCurlSettingsArray(RequestInterface $request)
Making this method public.
curlExec($curlHandle)
Calls curl_exec.
foreach($paths as $path) $request
The Request class represents a single HTTP request.
parseCurlResult($response, $curlHandle)
Making this method public.
testCreateCurlSettingsArrayPUTStream()
This exception represents a HTTP error coming from the Client.
testCreateCurlSettingsArrayGETAfterHEAD()
doRequest(RequestInterface $request)
This method is responsible for performing a single request.
if($_SERVER['argc']< 4) $client
getHeaders()
Returns all the HTTP headers as an array.
getResponse()
Returns the full response object.
testCreateCurlSettingsArrayGET()
testCreateCurlSettingsArrayPUTString()
curlStuff($curlHandle)
Returns a bunch of information about a curl request.
This class represents a single HTTP response.
emit($eventName, array $arguments=[], callable $continueCallBack=null)
Emits an event.
getBodyAsString()
Returns the body as a string.
const VERSION
Full version number.
testCreateCurlSettingsArrayHEAD()
A rudimentary HTTP client.