# HG changeset patch # User Dan # Date 1269826777 14400 # Node ID a54e149f4a78b280a1d3268b701088f487a05b77 # Parent 7dca925b0209af7c3bedcab4c81f706f70fec098 Added https support in Request_HTTP diff -r 7dca925b0209 -r a54e149f4a78 includes/http.php --- a/includes/http.php Sat Mar 20 16:05:38 2010 -0400 +++ b/includes/http.php Sun Mar 28 21:39:37 2010 -0400 @@ -188,6 +188,13 @@ var $socket = false; /** + * True if SSL is on, defaults to false + * @var bool + */ + + var $ssl = false; + + /** * The state of our request. 0 means it hasn't been made yet. 1 means the socket is open, 2 means the socket is open and the request has been written, 3 means the headers have been fetched, and 4 means the request is completed. * @var int */ @@ -200,12 +207,23 @@ * @param string URI (/index.php) * @param string Request method - GET or POST. * @param int Optional. The port to open the request on. Defaults to 80. + * @param bool If true, uses SSL (and defaults the port to 443) */ - function Request_HTTP($host, $uri, $method = 'GET', $port = 80) + function Request_HTTP($host, $uri, $method = 'GET', $port = 'default', $ssl = false) { if ( !preg_match('/^(?:(([a-z0-9-]+\.)*?)([a-z0-9-]+)|\[[a-f0-9:]+\])$/', $host) ) throw new Exception(__CLASS__ . ': Invalid hostname'); + if ( $ssl ) + { + $this->ssl = true; + $port = ( $port === 'default' ) ? 443 : $port; + } + else + { + $this->ssl = false; + $port = ( $port === 'default' ) ? 80 : $port; + } // Yes - this really does support IPv6 URLs! $this->host = $host; $this->uri = $uri; @@ -333,7 +351,8 @@ function _sock_open(&$connection) { // Open connection - $connection = fsockopen($this->host, $this->port, $errno, $errstr); + $ssl_prepend = ( $this->ssl ) ? 'ssl://' : ''; + $connection = fsockopen($ssl_prepend . $this->host, $this->port, $errno, $errstr); if ( !$connection ) throw new Exception(__METHOD__ . ": Could not make connection"); // to {$this->host}:{$this->port}: error $errno: $errstr"); @@ -409,6 +428,7 @@ } fclose($connection); + $this->state = 0; } /**