* @param integer $timeout
* @param array $options
*/
- public function __construct($host, $port, $timeout = 30, $options = array()) {
+ public function __construct($host, $port, $timeout = 3) {
$this->host = $host;
$this->port = $port;
- if (count($options)) {
- $context = stream_context_create($options);
- $this->resource = fsockopen($host, $port, $this->errorNumber, $this->errorDesc, $timeout, $context);
- }
- else {
- $this->resource = fsockopen($host, $port, $this->errorNumber, $this->errorDesc, $timeout);
- }
+
+ $this->resource = fsockopen($host, $port, $this->errorNumber, $this->errorDesc, $timeout);
if ($this->resource === false) {
throw new SystemException('Can not connect to ' . $host);
}
$newFileName = self::getTemporaryFilename($prefix.'_');
$localFile = new File($newFileName); // the file to write.
- // parse options
- if (PROXY_SERVER_HTTP) {
- $options['http']['proxy'] = PROXY_SERVER_HTTP;
- $options['http']['request_fulluri'] = true;
- }
- $timeout = 30;
- if (isset($options['timeout'])) {
- $timeout = $options['timeout'];
- unset($options['timeout']);
+ if (!isset($options['timeout'])) {
+ $options['timeout'] = 30;
}
- $method = (!empty($postParameters) ? 'POST' : 'GET');
- if (isset($options['method'])) {
- $method = $options['method'];
- unset($options['method']);
+ if (!isset($options['method'])) {
+ $options['method'] = (!empty($postParameters) ? 'POST' : 'GET');
}
// parse URL
$port = ($parsedUrl['scheme'] == 'https' ? 443 : 80);
$host = $parsedUrl['host'];
$path = (isset($parsedUrl['path']) ? $parsedUrl['path'] : '/');
+ // proxy is set
+ if (PROXY_SERVER_HTTP) {
+ $parsedProxy = parse_url(PROXY_SERVER_HTTP);
+ $host = $parsedProxy['host'];
+ $port = ($parsedProxy['scheme'] == 'https' ? 443 : 80);
+ $path = $httpUrl;
+ $parsedUrl['query'] = '';
+ }
// build parameter-string
$parameterString = '';
// connect
try {
- $remoteFile = new RemoteFile(($parsedUrl['scheme'] == 'https' ? 'ssl://' : '').$host, $port, $timeout, $options);
+ $remoteFile = new RemoteFile(($port === 443 ? 'ssl://' : '').$host, $port, $options['timeout']);
}
catch (SystemException $e) {
$localFile->close();
}
// build and send the http request.
- $request = $method." ".$path.(!empty($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '')." HTTP/1.0\r\n";
+ $request = $options['method']." ".$path.(!empty($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '')." HTTP/1.0\r\n";
$request .= "User-Agent: HTTP.PHP (FileUtil.class.php; WoltLab Community Framework/".WCF_VERSION."; ".WCF::getLanguage()->languageCode.")\r\n";
$request .= "Accept: */*\r\n";
$request .= "Accept-Language: ".WCF::getLanguage()->languageCode."\r\n";