Permalink
Browse files

Fixes #3686 - Request_Client_External does not restore Request::$curr…

…ent when an error occors during execute()
  • Loading branch information...
1 parent b7cbf71 commit 20a63514d6e6b8cc520cd71a7506dcf79544ffd3 @kiall kiall committed Feb 2, 2011
Showing with 31 additions and 13 deletions.
  1. +31 −13 classes/kohana/request/client/external.php
@@ -93,30 +93,48 @@ public function execute(Request $request)
$previous = Request::$current;
Request::$current = $request;
- // If PECL_HTTP is present, use extension to complete request
- if (extension_loaded('http'))
- {
- $this->_http_execute($request);
- }
- // Else if CURL is present, use extension to complete request
- elseif (extension_loaded('curl'))
+ try
{
- $this->_curl_execute($request);
+ // If PECL_HTTP is present, use extension to complete request
+ if (extension_loaded('http'))
+ {
+ $this->_http_execute($request);
+ }
+ // Else if CURL is present, use extension to complete request
+ elseif (extension_loaded('curl'))
+ {
+ $this->_curl_execute($request);
+ }
+ // Else use the sloooow method
+ else
+ {
+ $this->_native_execute($request);
+ }
}
- // Else use the sloooow method
- else
+ catch (Exception $e)
{
- $this->_native_execute($request);
+ // Restore the previous request
+ Request::$current = $previous;
+
+ if (isset($benchmark))
+ {
+ // Delete the benchmark, it is invalid
+ Profiler::delete($benchmark);
+ }
+
+ // Re-throw the exception
+ throw $e;
}
+ // Restore the previous request
+ Request::$current = $previous;
+
if (isset($benchmark))
{
// Stop the benchmark
Profiler::stop($benchmark);
}
- Request::$current = $previous;
-
// Cache the response if cache is available
if ($this->_cache instanceof Cache)
{

0 comments on commit 20a6351

Please sign in to comment.