// Parse the URL, and make sure we can handle the schema. $uri = parse_url($url); switch ($uri['scheme']) { case 'http': // $port = isset($uri['port']) ? $uri['port'] : 80; // $host = $uri['host'] . ($port != 80 ? ':'. $port : ''); // $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15); $fp = @fsockopen('http://proxy.address.tld', '80'); break; case 'https': // Note: Only works for PHP 4.3 compiled with OpenSSL. $port = isset($uri['port']) ? $uri['port'] : 443; $host = $uri['host'] . ($port != 443 ? ':'. $port : ''); $fp = @fsockopen('ssl://'. $uri['host'], $port, $errno, $errstr, 20); break; default: $result->error = 'invalid schema '. $uri['scheme']; return $result; } // Make sure the socket opened properly. if (!$fp) { $result->error = trim($errno .' '. $errstr); return $result; } // Construct the path to act on. $path = isset($uri['path']) ? $uri['path'] : '/'; if (isset($uri['query'])) { $path .= '?'. $uri['query']; } // Create HTTP request. $defaults = array( // RFC 2616: "non-standard ports MUST, default ports MAY be included". // We don't add the port to prevent from breaking rewrite rules checking // the host that do not take into account the port number. 'Host' => "Host: $host", 'User-Agent' => 'User-Agent: Drupal (+http://drupal.org/)', 'Content-Length' => 'Content-Length: '. strlen($data) ); foreach ($headers as $header => $value) { $defaults[$header] = $header .': '. $value; } // $request = $method .' '. $path ." HTTP/1.0\r\n"; $request = '$method '.$uri['scheme'].'://'.$uri['host'].$path.' HTTP/1.1\r\n'; // $request .= implode("\r\n", $defaults); $request .= "\r\n\r\n"; if ($data) { $request .= $data ."\r\n"; } $result->request = $request;