From a195ffa6b1d139143e57edcffc9cd3d9b40236a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 22 Nov 2012 21:45:39 +0100 Subject: [PATCH] HTTPUtil -> HTTPRequest and add comments to HTTPRequest --- wcfsetup/install/files/lib/util/FileUtil.class.php | 2 +- .../{HTTPUtil.class.php => HTTPRequest.class.php} | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) rename wcfsetup/install/files/lib/util/{HTTPUtil.class.php => HTTPRequest.class.php} (96%) diff --git a/wcfsetup/install/files/lib/util/FileUtil.class.php b/wcfsetup/install/files/lib/util/FileUtil.class.php index 9ffeb1258a..0e138921ad 100644 --- a/wcfsetup/install/files/lib/util/FileUtil.class.php +++ b/wcfsetup/install/files/lib/util/FileUtil.class.php @@ -401,7 +401,7 @@ final class FileUtil { * from now on, as this method may be removed in the future. */ public static function downloadFileFromHttp($httpUrl, $prefix = 'package', array $options = array(), array $postParameters = array(), &$headers = array()) { - $request = new HTTPUtil($httpUrl, $options, $postParameters); + $request = new HTTPRequest($httpUrl, $options, $postParameters); $request->execute(); $reply = $request->getReply(); diff --git a/wcfsetup/install/files/lib/util/HTTPUtil.class.php b/wcfsetup/install/files/lib/util/HTTPRequest.class.php similarity index 96% rename from wcfsetup/install/files/lib/util/HTTPUtil.class.php rename to wcfsetup/install/files/lib/util/HTTPRequest.class.php index 2b464db28c..f76de1aebb 100644 --- a/wcfsetup/install/files/lib/util/HTTPUtil.class.php +++ b/wcfsetup/install/files/lib/util/HTTPRequest.class.php @@ -6,7 +6,7 @@ use wcf\system\Regex; use wcf\system\WCF; /** - * HTTPUtil sends HTTP requests. + * HTTPRequest sends HTTP requests. * It supports POST, SSL, Basic Auth etc. * * @author Tim Düsterhus @@ -16,7 +16,7 @@ use wcf\system\WCF; * @subpackage util * @category Community Framework */ -final class HTTPUtil { +final class HTTPRequest { /** * given options * @var array @@ -97,6 +97,7 @@ final class HTTPUtil { $this->setOptions($options); + // set default headers $this->addHeader('User-Agent', "HTTP.PHP (HTTPUtil.class.php; WoltLab Community Framework/".WCF_VERSION."; ".WCF::getLanguage()->languageCode.")"); $this->addHeader('Accept', '*/*'); $this->addHeader('Accept-Language', WCF::getLanguage()->languageCode); @@ -141,12 +142,14 @@ final class HTTPUtil { $request = $this->options['method']." ".$this->path.($this->query ? '?'.$this->query : '')." HTTP/1.0\r\n"; + // add headers foreach ($this->headers as $name => $values) { foreach ($values as $value) { $request .= $name.": ".$value."\r\n"; } } $request .= "\r\n"; + // add post parameters if ($this->options['method'] !== 'GET') $request .= http_build_query($this->postParameters)."\r\n\r\n"; $remoteFile->puts($request); @@ -231,6 +234,7 @@ final class HTTPUtil { break; } + // validate length if (isset($this->replyHeaders['Content-Length'])) { if (strlen($this->replyBody) != $this->replyHeaders['Content-Length']) { throw new SystemException('Body length does not match length given in header'); @@ -244,7 +248,11 @@ final class HTTPUtil { * @return array */ public function getReply() { - return array('statusCode' => $this->statusCode, 'headers' => $this->replyHeaders, 'body' => $this->replyBody); + return array( + 'statusCode' => $this->statusCode, + 'headers' => $this->replyHeaders, + 'body' => $this->replyBody + ); } /** -- 2.20.1