summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-02-11 23:01:29 +0100
committerAndreas Gohr <andi@splitbrain.org>2014-02-11 23:02:44 +0100
commit2bbe40cf8802bbc3bbf83d454cc294080ebaf241 (patch)
tree6e2b825a13b733c6496bdefbb130385dd900ae9f /inc
parent44e51f2fde494e6183b60153246c72bacef88ad7 (diff)
downloadrpg-2bbe40cf8802bbc3bbf83d454cc294080ebaf241.tar.gz
rpg-2bbe40cf8802bbc3bbf83d454cc294080ebaf241.tar.bz2
HTTPClient: correctly abort a proxy connection
if a needed CONNECT tunnel fails
Diffstat (limited to 'inc')
-rw-r--r--inc/HTTPClient.php23
1 files changed, 16 insertions, 7 deletions
diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php
index 96954fb47..2226103b3 100644
--- a/inc/HTTPClient.php
+++ b/inc/HTTPClient.php
@@ -304,11 +304,18 @@ class HTTPClient {
}
// try establish a CONNECT tunnel for SSL
- if($this->_ssltunnel($socket, $request_url)){
- // no keep alive for tunnels
- $this->keep_alive = false;
- // tunnel is authed already
- if(isset($headers['Proxy-Authentication'])) unset($headers['Proxy-Authentication']);
+ try {
+ if($this->_ssltunnel($socket, $request_url)){
+ // no keep alive for tunnels
+ $this->keep_alive = false;
+ // tunnel is authed already
+ if(isset($headers['Proxy-Authentication'])) unset($headers['Proxy-Authentication']);
+ }
+ } catch (HTTPClientException $e) {
+ $this->status = $e->getCode();
+ $this->error = $e->getMessage();
+ fclose($socket);
+ return false;
}
// keep alive?
@@ -363,7 +370,7 @@ class HTTPClient {
// get Status
if (!preg_match('/^HTTP\/(\d\.\d)\s*(\d+).*?\n/', $r_headers, $m))
- throw new HTTPClientException('Server returned bad answer');
+ throw new HTTPClientException('Server returned bad answer '.$r_headers);
$this->status = $m[2];
@@ -526,6 +533,7 @@ class HTTPClient {
*
* @param resource &$socket
* @param string &$requesturl
+ * @throws HTTPClientException when a tunnel is needed but could not be established
* @return bool true if a tunnel was established
*/
function _ssltunnel(&$socket, &$requesturl){
@@ -559,7 +567,8 @@ class HTTPClient {
return true;
}
}
- return false;
+
+ throw new HTTPClientException('Failed to establish secure proxy connection', -150);
}
/**