Created
February 10, 2012 15:18
-
-
Save kiall/1790222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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