Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fruux/sabre-http
Browse files Browse the repository at this point in the history
Conflicts:
	lib/URLUtil.php
  • Loading branch information
evert committed Dec 7, 2014
2 parents 9bdb0f5 + acb39bb commit 8ab5184
Show file tree
Hide file tree
Showing 31 changed files with 115 additions and 102 deletions.
10 changes: 8 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
ChangeLog
=========

3.0.3 (????-??-??)
3.0.4 (201?-??-??)
------------------

* Hiding `Authorization` header value from `Request::__toString`.
* #38: The Authentication helpers no longer overwrite any existing
`WWW-Authenticate` headers, but instead append new headers. This ensures
that multiple authentication systems can exist in the same environment.


3.0.3 (2014-12-03)
------------------

* Hiding `Authorization` header value from `Request::__toString`.


3.0.2 (2014-10-09)
------------------

Expand Down
52 changes: 24 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ effectively a wrapper around the following PHP constructs:

For Input:

* `$_GET`
* `$_POST`
* `$_SERVER`
* `$_GET`,
* `$_POST`,
* `$_SERVER`,
* `php://input` or `$HTTP_RAW_POST_DATA`.

For output:

* `php://output` or `echo`.
* `header()`
* `php://output` or `echo`,
* `header()`.

What this library provides, is a `Request` object, and a `Response` object.

Expand All @@ -39,7 +39,6 @@ Installation
Make sure you have [composer][1] installed. In your project directory, create,
or edit a `composer.json` file, and make sure it contains something like this:


```json
{
"require" : {
Expand All @@ -53,18 +52,18 @@ After that, just hit `composer install` and you should be rolling.
Quick history
-------------

This library came to existence in 2009, as a part of the [SabreDAV][2]
This library came to existence in 2009, as a part of the [`sabre/dav`][2]
project, which uses it heavily.

It got split off into a separate library to make it easier to manage
releases and hopefully giving it use outside of the scope of just SabreDAV.
releases and hopefully giving it use outside of the scope of just `sabre/dav`.

Although completely independently developed, this library has a LOT of
overlap with [symfony's HttpFoundation][3].
overlap with [Symfony's `HttpFoundation`][3].

Said library does a lot more stuff and is significantly more popular,
so if you are looking for something to fulfill this particular requirement,
I'd recommend also considering [HttpFoundation][3].
I'd recommend also considering [`HttpFoundation`][3].


Getting started
Expand Down Expand Up @@ -96,7 +95,6 @@ function handleRequest(HTTP\RequestInterface $request) {

A response object you can just create as such:


```php
use Sabre\HTTP;

Expand All @@ -120,29 +118,28 @@ HTTP\Sapi::sendResponse($response);
This line should generally also appear once in your application (at the very
end).


Decorators
----------

It may be useful to extend the Request and Response objects in your
It may be useful to extend the `Request` and `Response` objects in your
application, if you for example would like them to carry a bit more
information about the current request.

For instance, you may want to add an `isLoggedIn()` method to the Request
For instance, you may want to add an `isLoggedIn` method to the Request
object.

Simply extending Request and Response may pose some problems:

1. You may want to extend the objects with new behavior differently, in
different subsystems of your application.
1. You may want to extend the objects with new behaviors differently, in
different subsystems of your application,
2. The `Sapi::getRequest` factory always returns a instance of
`Request` so you would have to override the factory method as well.
`Request` so you would have to override the factory method as well,
3. By controlling the instantation and depend on specific `Request` and
`Response` instances in your library or application, you make it harder to
work with other applications which also use `sabre/http`.

In short: it would be bad design. Instead, it's recommended to use the
[decorator pattern][6] to add new behavior where you need it. sabre/http
[decorator pattern][6] to add new behavior where you need it. `sabre/http`
provides helper classes to quickly do this.

Example:
Expand Down Expand Up @@ -185,8 +182,8 @@ This package also contains a simple wrapper around [cURL][4], which will allow
you to write simple clients, using the `Request` and `Response` objects you're
already familiar with.

It's by no means a replacement for something like [guzzle][7], but it provides
a simple and lightweight api for making the occasional API call.
It's by no means a replacement for something like [Guzzle][7], but it provides
a simple and lightweight API for making the occasional API call.

### Usage

Expand All @@ -202,7 +199,7 @@ $response = $client->send($request);
echo $response->getBodyAsString();
```

The client emits 3 event using [sabre/event][5]. `beforeRequest`,
The client emits 3 event using [`sabre/event`][5]. `beforeRequest`,
`afterRequest` and `error`.

```php
Expand Down Expand Up @@ -245,11 +242,11 @@ $client->on('error:401', function($request, $response, &$retry, $retryCount) {

### Asynchronous requests

The Client also supports doing asynchronous requests. This is especially handy
The `Client` also supports doing asynchronous requests. This is especially handy
if you need to perform a number of requests, that are allowed to be executed
in parallel.

The underlying system for this is simply [curl's multi request handler][8],
The underlying system for this is simply [cURL's multi request handler][8],
but this provides a much nicer API to handle this.

Sample usage:
Expand Down Expand Up @@ -279,7 +276,7 @@ $client->wait();

```

Check out examples/asyncclient.php for more information.
Check out `examples/asyncclient.php` for more information.

Writing a reverse proxy
-----------------------
Expand Down Expand Up @@ -323,7 +320,6 @@ $response = $client->send($subRequest);
Sapi::sendResponse($response);
```


The Request and Response API's
------------------------------

Expand Down Expand Up @@ -741,10 +737,10 @@ Made at fruux
This library is being developed by [fruux](https://fruux.com/). Drop us a line for commercial services or enterprise support.

[1]: http://getcomposer.org/
[2]: http://code.google.com/p/sabredav
[2]: http://sabre.io/
[3]: https://github.com/symfony/HttpFoundation
[4]: http://uk3.php.net/curl
[4]: http://php.net/curl
[5]: https://github.com/fruux/sabre-event
[6]: http://en.wikipedia.org/wiki/Decorator_pattern
[7]: http://guzzlephp.org/
[8]: http://www.php.net/manual/en/function.curl-multi-init.php
[8]: http://php.net/curl_multi_init
File renamed without changes.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"authors" : [
{
"name" : "Evert Pot",
"email" : "evert@rooftopsolutions.nl",
"homepage" : "http://www.rooftopsolutions.nl/",
"email" : "me@evertpot.com",
"homepage" : "http://evertpot.com/",
"role" : "Developer"
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/asyncclient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH. All rights reserved.
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/

use
Expand Down
2 changes: 1 addition & 1 deletion examples/basicauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* *
* @copyright Copyright (C) 2009-2014 fruux GmbH. All rights reserved.
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/

$userList = [
Expand Down
2 changes: 1 addition & 1 deletion examples/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH. All rights reserved.
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/

use
Expand Down
2 changes: 1 addition & 1 deletion examples/stringify.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH. All rights reserved.
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/

use
Expand Down
9 changes: 7 additions & 2 deletions lib/Auth/AWS.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/
class AWS extends AbstractAuth {

Expand Down Expand Up @@ -215,9 +215,14 @@ protected function getAmzHeaders() {
*/
private function hmacsha1($key, $message) {

if (function_exists('hash_hmac')) {
return hash_hmac('sha1', $message, $key, true);
}

$blocksize=64;
if (strlen($key)>$blocksize)
if (strlen($key)>$blocksize) {
$key=pack('H*', sha1($key));
}
$key=str_pad($key,$blocksize,chr(0x00));
$ipad=str_repeat(chr(0x36),$blocksize);
$opad=str_repeat(chr(0x5c),$blocksize);
Expand Down
2 changes: 1 addition & 1 deletion lib/Auth/AbstractAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/
abstract class AbstractAuth {

Expand Down
2 changes: 1 addition & 1 deletion lib/Auth/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/
class Basic extends AbstractAuth {

Expand Down
2 changes: 1 addition & 1 deletion lib/Auth/Digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/
class Digest extends AbstractAuth {

Expand Down
12 changes: 6 additions & 6 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH. All rights reserved.
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/
class Client extends EventEmitter {

Expand Down Expand Up @@ -110,7 +110,7 @@ function send(RequestInterface $request) {

$oldLocation = $request->getUrl();

// Creating an new instance of the request object.
// Creating a new instance of the request object.
$request = clone $request;

// Setting the new location
Expand Down Expand Up @@ -150,7 +150,7 @@ function send(RequestInterface $request) {

$this->emit('afterRequest', [$request, $response]);

if ($this->throwExceptions && $code > 399) {
if ($this->throwExceptions && $code >= 400) {
throw new ClientHttpException($response);
}

Expand Down Expand Up @@ -286,10 +286,10 @@ function wait() {

/**
* If this is set to true, the Client will automatically throw exceptions
* upon http errors.
* upon HTTP errors.
*
* This means that if a response came back with a status code of 400 or
* higher, we will throw a ClientHttpException.
* This means that if a response came back with a status code greater than
* or equal to 400, we will throw a ClientHttpException.
*
* This only works for the send() method. Throwing exceptions for
* sendAsync() is not supported.
Expand Down
2 changes: 1 addition & 1 deletion lib/ClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH. All rights reserved.
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/
class ClientException extends \Exception {

Expand Down
2 changes: 1 addition & 1 deletion lib/ClientHttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH. All rights reserved.
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/
class ClientHttpException extends \Exception implements HttpException {

Expand Down
2 changes: 1 addition & 1 deletion lib/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @copyright Copyright (C) 2009-2014 fruux GmbH. All rights reserved.
* @author Evert Pot (http://evertpot.com/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
* @license http://sabre.io/license/ Modified BSD License
*/
interface HttpException {

Expand Down
Loading

0 comments on commit 8ab5184

Please sign in to comment.