diff options
author | Gerry Weißbach <gerry.w@gammaproduction.de> | 2014-12-22 10:31:30 +0100 |
---|---|---|
committer | Gerry Weißbach <gerry.w@gammaproduction.de> | 2014-12-22 10:31:30 +0100 |
commit | 8da2ebf4f4261eb8f54df5704b5d9af283b5402d (patch) | |
tree | 9c63975e3898c949e1784e30e81a5ed3da7fca93 /inc/HTTPClient.php | |
parent | 5e7f4d50cbbc788c9c0483a0a2ff1b536e4ffe8c (diff) | |
parent | 1bf4abb07f65e28578bae98aad457cb768d8b44f (diff) | |
download | rpg-8da2ebf4f4261eb8f54df5704b5d9af283b5402d.tar.gz rpg-8da2ebf4f4261eb8f54df5704b5d9af283b5402d.tar.bz2 |
Merge remote-tracking branch 'splitbrain/master'
Diffstat (limited to 'inc/HTTPClient.php')
-rw-r--r-- | inc/HTTPClient.php | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index cd4c7c4c5..76d973c38 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -57,6 +57,12 @@ class DokuHTTPClient extends HTTPClient { * @triggers HTTPCLIENT_REQUEST_SEND * @author Andreas Gohr <andi@splitbrain.org> */ + /** + * @param string $url + * @param string|array $data the post data either as array or raw data + * @param string $method + * @return bool + */ function sendRequest($url,$data='',$method='GET'){ $httpdata = array('url' => $url, 'data' => $data, @@ -104,7 +110,7 @@ class HTTPClient { var $header_regexp; // if set this RE must match against the headers, else abort var $headers; var $debug; - var $start = 0; // for timings + var $start = 0.0; // for timings var $keep_alive = true; // keep alive rocks // don't set these, read on error @@ -166,7 +172,8 @@ class HTTPClient { * * @param string $url The URL to fetch * @param bool $sloppy304 Return body on 304 not modified - * @return bool|string response body, false on error + * @return false|string response body, false on error + * * @author Andreas Gohr <andi@splitbrain.org> */ function get($url,$sloppy304=false){ @@ -187,7 +194,8 @@ class HTTPClient { * @param string $url The URL to fetch * @param array $data Associative array of parameters * @param bool $sloppy304 Return body on 304 not modified - * @return bool|string response body, false on error + * @return false|string response body, false on error + * * @author Andreas Gohr <andi@splitbrain.org> */ function dget($url,$data,$sloppy304=false){ @@ -207,7 +215,7 @@ class HTTPClient { * * @param string $url The URL to fetch * @param array $data Associative array of parameters - * @return bool|string response body, false on error + * @return false|string response body, false on error * @author Andreas Gohr <andi@splitbrain.org> */ function post($url,$data){ @@ -229,6 +237,7 @@ class HTTPClient { * @param mixed $data - the post data either as array or raw data * @param string $method - HTTP Method usually GET or POST. * @return bool - true on success + * * @author Andreas Goetz <cpuidle@gmx.de> * @author Andreas Gohr <andi@splitbrain.org> */ @@ -580,7 +589,18 @@ class HTTPClient { $this->_debug('SSL Tunnel Response',$r_headers); if(preg_match('/^HTTP\/1\.[01] 200/i',$r_headers)){ - if (stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_SSLv3_CLIENT)) { + // set correct peer name for verification (enabled since PHP 5.6) + stream_context_set_option($socket, 'ssl', 'peer_name', $requestinfo['host']); + + // Because of older PHP versions having trouble with TLS (enable_crypto returns true, but + // the conection still borks) we try SSLv3 first + if (@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_SSLv3_CLIENT)) { + $requesturl = $requestinfo['path']; + return true; + } + + // If the proxy does not support SSLv3 we try TLS + if (@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { $requesturl = $requestinfo['path']; return true; } @@ -596,6 +616,7 @@ class HTTPClient { * @param string $data The data to write * @param string $message Description of what is being read * @throws HTTPClientException + * * @author Tom N Harris <tnharris@whoopdedo.org> */ function _sendData($socket, $data, $message) { @@ -640,6 +661,7 @@ class HTTPClient { * @param bool $ignore_eof End-of-file is not an error if this is set * @throws HTTPClientException * @return string + * * @author Tom N Harris <tnharris@whoopdedo.org> */ function _readData($socket, $nbytes, $message, $ignore_eof = false) { @@ -689,6 +711,7 @@ class HTTPClient { * @param string $message Description of what is being read * @throws HTTPClientException * @return string + * * @author Tom N Harris <tnharris@whoopdedo.org> */ function _readLine($socket, $message) { @@ -723,6 +746,9 @@ class HTTPClient { * Uses _debug_text or _debug_html depending on the SAPI name * * @author Andreas Gohr <andi@splitbrain.org> + * + * @param string $info + * @param mixed $var */ function _debug($info,$var=null){ if(!$this->debug) return; @@ -736,8 +762,8 @@ class HTTPClient { /** * print debug info as HTML * - * @param $info - * @param null $var + * @param string $info + * @param mixed $var */ function _debug_html($info, $var=null){ print '<b>'.$info.'</b> '.($this->_time() - $this->start).'s<br />'; @@ -753,8 +779,8 @@ class HTTPClient { /** * prints debug info as plain text * - * @param $info - * @param null $var + * @param string $info + * @param mixed $var */ function _debug_text($info, $var=null){ print '*'.$info.'* '.($this->_time() - $this->start)."s\n"; @@ -764,6 +790,8 @@ class HTTPClient { /** * Return current timestamp in microsecond resolution + * + * @return float */ static function _time(){ list($usec, $sec) = explode(" ", microtime()); @@ -776,6 +804,9 @@ class HTTPClient { * All Keys are lowercased. * * @author Andreas Gohr <andi@splitbrain.org> + * + * @param string $string + * @return array */ function _parseHeaders($string){ $headers = array(); @@ -804,6 +835,9 @@ class HTTPClient { * convert given header array to header string * * @author Andreas Gohr <andi@splitbrain.org> + * + * @param array $headers + * @return string */ function _buildHeaders($headers){ $string = ''; @@ -818,6 +852,8 @@ class HTTPClient { * get cookies as http header string * * @author Andreas Goetz <cpuidle@gmx.de> + * + * @return string */ function _getCookies(){ $headers = ''; @@ -833,6 +869,9 @@ class HTTPClient { * Encode data for posting * * @author Andreas Gohr <andi@splitbrain.org> + * + * @param array $data + * @return string */ function _postEncode($data){ return http_build_query($data,'','&'); @@ -843,6 +882,9 @@ class HTTPClient { * * @fixme use of urlencode might be wrong here * @author Andreas Gohr <andi@splitbrain.org> + * + * @param array $data + * @return string */ function _postMultipartEncode($data){ $boundary = '--'.$this->boundary; |