Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add documentation about automatic handling of a redirect response. #239

Merged
merged 3 commits into from Mar 30, 2012
Jump to file or symbol
Failed to load files and symbols.
+25 −0
Split
@@ -105,6 +105,7 @@ HTTP methods.
'User-Agent' => 'CakePHP'
),
'raw' => null,
+ 'redirect' => false,
'cookies' => array()
);
@@ -145,8 +146,10 @@ The ``HttpResponse`` also exposes the following methods:
* ``body()`` returns the body
* ``isOk()`` returns if code is 200;
+* ``isRedirect()`` returns if code is 301, 302, 303 or 307 and the *Location* header is set.
* ``getHeader()`` allows you to fetch headers, see the next section.
+
Getting headers from a response
-------------------------------
@@ -179,6 +182,28 @@ You could fetch the above headers by calling::
Headers can be fetched case-insensitively.
+Automaticaly handling a redirect response
+----------------------------------------
+
+When the response has a valid redirect status code (see ``HttpResponse::isRedirect``),
+an extra request can be automaticaly done according to the received *Location* header::
+
+ <?php
+ App::uses('HttpSocket', 'Network/Http');
+
+ $HttpSocket = new HttpSocket();
+ $response = $HttpSocket->get('http://example.com/redirecting_url', array(), array('redirect' => true));
+
+
+The *redirect* option can take the following values
+
+* **true** : all redirecting responses will fire a consequent new request
+* **integer** : the setted value is the maximum number of redirections allowed (after reaching it, the *redirect* value is condidered as **false**)
+* **false** (default) : no consequent request will be fired
+
+The returned ``$response`` will be the final one, according to the settings.
+
+
Creating a custom response class
--------------------------------