generated from Nodarx/template
Initial service DAV module
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This example demonstrates the ability for clients to work asynchronously.
|
||||
*
|
||||
* By default up to 10 requests will be executed in parallel. HTTP connections
|
||||
* are re-used and DNS is cached, all thanks to the power of curl.
|
||||
*
|
||||
* @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
use Sabre\HTTP\Client;
|
||||
use Sabre\HTTP\Request;
|
||||
|
||||
// Find the autoloader
|
||||
$paths = [
|
||||
__DIR__.'/../vendor/autoload.php',
|
||||
__DIR__.'/../../../autoload.php',
|
||||
__DIR__.'/vendor/autoload.php',
|
||||
];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path)) {
|
||||
include $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// This is the request we're repeating 1000 times.
|
||||
$request = new Request('GET', 'http://localhost/');
|
||||
$client = new Client();
|
||||
|
||||
for ($i = 0; $i < 1000; ++$i) {
|
||||
echo "$i sending\n";
|
||||
$client->sendAsync(
|
||||
$request,
|
||||
|
||||
// This is the 'success' callback
|
||||
function ($response) use ($i) {
|
||||
echo "$i -> ".$response->getStatus()."\n";
|
||||
},
|
||||
|
||||
// This is the 'error' callback. It is called for general connection
|
||||
// problems (such as not being able to connect to a host, dns errors,
|
||||
// etc.) and also cases where a response was returned, but it had a
|
||||
// status code of 400 or higher.
|
||||
function ($error) use ($i) {
|
||||
if (Client::STATUS_CURLERROR === $error['status']) {
|
||||
// Curl errors
|
||||
echo "$i -> curl error: ".$error['curl_errmsg']."\n";
|
||||
} else {
|
||||
// HTTP errors
|
||||
echo "$i -> ".$error['response']->getStatus()."\n";
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// After everything is done, we call 'wait'. This causes the client to wait for
|
||||
// all outstanding http requests to complete.
|
||||
$client->wait();
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This example shows how to do Basic authentication.
|
||||
* *.
|
||||
*
|
||||
* @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
$userList = [
|
||||
'user1' => 'password',
|
||||
'user2' => 'password',
|
||||
];
|
||||
|
||||
use Sabre\HTTP\Auth;
|
||||
use Sabre\HTTP\Response;
|
||||
use Sabre\HTTP\Sapi;
|
||||
|
||||
// Find the autoloader
|
||||
$paths = [
|
||||
__DIR__.'/../vendor/autoload.php',
|
||||
__DIR__.'/../../../autoload.php',
|
||||
__DIR__.'/vendor/autoload.php',
|
||||
];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path)) {
|
||||
include $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$request = Sapi::getRequest();
|
||||
$response = new Response();
|
||||
|
||||
$basicAuth = new Auth\Basic('Locked down area', $request, $response);
|
||||
if (!$userPass = $basicAuth->getCredentials()) {
|
||||
// No username or password given
|
||||
$basicAuth->requireLogin();
|
||||
} elseif (!isset($userList[$userPass[0]]) || $userList[$userPass[0]] !== $userPass[1]) {
|
||||
// Username or password are incorrect
|
||||
$basicAuth->requireLogin();
|
||||
} else {
|
||||
// Success !
|
||||
$response->setBody('You are logged in!');
|
||||
}
|
||||
|
||||
// Sending the response
|
||||
Sapi::sendResponse($response);
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This example shows how to make a HTTP request with the Request and Response
|
||||
* objects.
|
||||
*
|
||||
* @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
use Sabre\HTTP\Client;
|
||||
use Sabre\HTTP\Request;
|
||||
|
||||
// Find the autoloader
|
||||
$paths = [
|
||||
__DIR__.'/../vendor/autoload.php',
|
||||
__DIR__.'/../../../autoload.php',
|
||||
__DIR__.'/vendor/autoload.php',
|
||||
];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path)) {
|
||||
include $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructing the request.
|
||||
$request = new Request('GET', 'http://localhost/');
|
||||
|
||||
$client = new Client();
|
||||
// $client->addCurlSetting(CURLOPT_PROXY,'localhost:8888');
|
||||
$response = $client->send($request);
|
||||
|
||||
echo "Response:\n";
|
||||
|
||||
echo (string) $response;
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This example shows how to do Digest authentication.
|
||||
* *.
|
||||
*
|
||||
* @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
|
||||
* @author Markus Staab
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
$userList = [
|
||||
'user1' => 'password',
|
||||
'user2' => 'password',
|
||||
];
|
||||
|
||||
use Sabre\HTTP\Auth;
|
||||
use Sabre\HTTP\Response;
|
||||
use Sabre\HTTP\Sapi;
|
||||
|
||||
// Find the autoloader
|
||||
$paths = [
|
||||
__DIR__.'/../vendor/autoload.php',
|
||||
__DIR__.'/../../../autoload.php',
|
||||
__DIR__.'/vendor/autoload.php',
|
||||
];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path)) {
|
||||
include $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$request = Sapi::getRequest();
|
||||
$response = new Response();
|
||||
|
||||
$digestAuth = new Auth\Digest('Locked down area', $request, $response);
|
||||
$digestAuth->init();
|
||||
if (!$userName = $digestAuth->getUsername()) {
|
||||
// No username given
|
||||
$digestAuth->requireLogin();
|
||||
} elseif (!isset($userList[$userName]) || !$digestAuth->validatePassword($userList[$userName])) {
|
||||
// Username or password are incorrect
|
||||
$digestAuth->requireLogin();
|
||||
} else {
|
||||
// Success !
|
||||
$response->setBody('You are logged in!');
|
||||
}
|
||||
|
||||
// Sending the response
|
||||
Sapi::sendResponse($response);
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
// The url we're proxying to.
|
||||
$remoteUrl = 'http://example.org/';
|
||||
|
||||
// The url we're proxying from. Please note that this must be a relative url,
|
||||
// and basically acts as the base url.
|
||||
//
|
||||
// If your $remoteUrl doesn't end with a slash, this one probably shouldn't
|
||||
// either.
|
||||
$myBaseUrl = '/reverseproxy.php';
|
||||
// $myBaseUrl = '/~evert/sabre/http/examples/reverseproxy.php/';
|
||||
|
||||
use Sabre\HTTP\Client;
|
||||
use Sabre\HTTP\Sapi;
|
||||
|
||||
// Find the autoloader
|
||||
$paths = [
|
||||
__DIR__.'/../vendor/autoload.php',
|
||||
__DIR__.'/../../../autoload.php',
|
||||
__DIR__.'/vendor/autoload.php',
|
||||
];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path)) {
|
||||
include $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$request = Sapi::getRequest();
|
||||
$request->setBaseUrl($myBaseUrl);
|
||||
|
||||
$subRequest = clone $request;
|
||||
|
||||
// Removing the Host header.
|
||||
$subRequest->removeHeader('Host');
|
||||
|
||||
// Rewriting the url.
|
||||
$subRequest->setUrl($remoteUrl.$request->getPath());
|
||||
|
||||
$client = new Client();
|
||||
|
||||
// Sends the HTTP request to the server
|
||||
$response = $client->send($subRequest);
|
||||
|
||||
// Sends the response back to the client that connected to the proxy.
|
||||
Sapi::sendResponse($response);
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This simple example shows the capability of Request and Response objects to
|
||||
* serialize themselves as strings.
|
||||
*
|
||||
* This is mainly useful for debugging purposes.
|
||||
*
|
||||
* @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
use Sabre\HTTP\Request;
|
||||
use Sabre\HTTP\Response;
|
||||
|
||||
// Find the autoloader
|
||||
$paths = [
|
||||
__DIR__.'/../vendor/autoload.php',
|
||||
__DIR__.'/../../../autoload.php',
|
||||
__DIR__.'/vendor/autoload.php',
|
||||
];
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path)) {
|
||||
include $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$request = new Request('POST', '/foo');
|
||||
$request->setHeaders([
|
||||
'Host' => 'example.org',
|
||||
'Content-Type' => 'application/json',
|
||||
]);
|
||||
|
||||
$request->setBody(json_encode(['foo' => 'bar']));
|
||||
|
||||
echo $request;
|
||||
echo "\r\n\r\n";
|
||||
|
||||
$response = new Response(424);
|
||||
$response->setHeaders([
|
||||
'Content-Type' => 'text/plain',
|
||||
'Connection' => 'close',
|
||||
]);
|
||||
|
||||
$response->setBody('ABORT! ABORT!');
|
||||
|
||||
echo $response;
|
||||
|
||||
echo "\r\n";
|
||||
Reference in New Issue
Block a user