+ /**
+ * Checks wether proxy configuration is used
+ *
+ * @return $isUsed Wether proxy is used
+ */
+ protected function isProxyUsed () {
+ // Do we have cache?
+ if (!isset($GLOBALS[__METHOD__])) {
+ // Determine it
+ $GLOBALS[__METHOD__] = (($this->getConfigInstance()->getConfigEntry('proxy_host') != '') && ($this->getConfigInstance()->getConfigEntry('proxy_port') > 0));
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__METHOD__];
+ }
+
+ /**
+ * Sets up a proxy tunnel for given hostname and through resource
+ *
+ * @param $host Host to connect to
+ * @param $port Port number to connect to
+ * @param $socketResource Resource of a socket
+ * @return $response Response array
+ */
+ protected function setupProxyTunnel ($host, $port, $socketResource) {
+ // Initialize array
+ $response = array('', '', '');
+ $proxyTunnel = '';
+
+ // Generate CONNECT request header
+ $proxyTunnel .= 'CONNECT ' . $host . ':' . $port . ' HTTP/1.1' . self::HTTP_EOL;
+ $proxyTunnel .= 'Host: ' . $host . ':' . $port . self::HTTP_EOL;
+ $proxyTunnel .= 'Proxy-Connection: Keep-Alive' . self::HTTP_EOL;
+
+ // Use login data to proxy? (username at least!)
+ if ($this->getConfigInstance()->getConfigEntry('proxy_username') != '') {
+ // Add it as well
+ $encodedAuth = base64_encode($this->getConfigInstance()->getConfigEntry('proxy_username') . ':' . $this->getConfigInstance()->getConfigEntry('proxy_password'));
+ $proxyTunnel .= 'Proxy-Authorization: Basic ' . $encodedAuth . self::HTTP_EOL;
+ } // END - if
+
+ // Add last new-line
+ $proxyTunnel .= self::HTTP_EOL;
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONSOLE-TOOLS: proxyTunnel=' . $proxyTunnel);
+
+ // Write request
+ fwrite($socketResource, $proxyTunnel);
+
+ // Got response?
+ if (feof($socketResource)) {
+ // No response received
+ return $response;
+ } // END - if
+
+ // Read the first line
+ $resp = trim(fgets($socketResource, 10240));
+ $respArray = explode(' ', $resp);
+ if (((strtolower($respArray[0]) !== 'http/1.0') && (strtolower($respArray[0]) !== 'http/1.1')) || ($respArray[1] != '200')) {
+ // Invalid response!
+ return $response;
+ } // END - if
+
+ // All fine!
+ return $respArray;
+ }
+