Skip to content

Instantly share code, notes, and snippets.

@kiall
Created February 10, 2012 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiall/1790578 to your computer and use it in GitHub Desktop.
Save kiall/1790578 to your computer and use it in GitHub Desktop.
diff --git a/classes/kohana/request.php b/classes/kohana/request.php
index 7eb5716..b146aaa 100644
--- a/classes/kohana/request.php
+++ b/classes/kohana/request.php
@@ -649,7 +649,7 @@ class Kohana_Request implements HTTP_Request {
* @uses Route::all
* @uses Route::matches
*/
- public function __construct($uri, HTTP_Cache $cache = NULL, $injected_routes = array())
+ public function __construct($uri, array $client_params = array(), $injected_routes = array())
{
// Initialise the header
$this->_header = new HTTP_Header(array());
@@ -726,7 +726,7 @@ class Kohana_Request implements HTTP_Request {
$this->_params = $params;
// Apply the client
- $this->_client = new Request_Client_Internal(array('cache' => $cache));
+ $this->_client = new Request_Client_Internal($client_params);
}
else
{
@@ -746,7 +746,7 @@ class Kohana_Request implements HTTP_Request {
$this->_external = TRUE;
// Setup the client
- $this->_client = Request_Client_External::factory(array('cache' => $cache));
+ $this->_client = Request_Client_External::factory($client_params);
}
}
diff --git a/classes/kohana/request/client.php b/classes/kohana/request/client.php
index 9e73b1c..83d12b8 100644
--- a/classes/kohana/request/client.php
+++ b/classes/kohana/request/client.php
@@ -64,7 +64,41 @@ abstract class Kohana_Request_Client {
if ($this->_cache instanceof HTTP_Cache)
return $this->_cache->execute($this, $request, $response);
- return $this->execute_request($request, $response);
+ $response = $this->execute_request($request, $response);
+
+ // TEMP - Move these somewhere accessible...
+ $follow = TRUE;
+ $follow_headers = array('Authorization');
+
+ // Do we need to follow a Location header ?
+ if ($follow AND in_array($response->status(), array(201, 301, 302, 303, 307))
+ AND $response->headers('Location'))
+ {
+ // Figure out which method to use for the follow request
+ switch ($response->status())
+ {
+ default:
+ case 301:
+ case 302:
+ case 307:
+ $follow_method = $request->method();
+ break;
+ case 201:
+ case 303:
+ $follow_method = Request::GET;
+ break;
+ }
+
+ // Prepare the additional request
+ $follow_request = Request::factory($response->headers('Location'))
+ ->method($follow_method)
+ ->headers(Arr::extract($request->headers(), $follow_headers));
+
+ // Execute the additional request
+ $response = $follow_request->execute();
+ }
+
+ return $response;
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment