diff --git a/httpclient.php b/httpclient.php index f4264b6..2ec8893 100644 --- a/httpclient.php +++ b/httpclient.php @@ -76,12 +76,16 @@ class Httpclient * If value is like "@/tmp/file", use the /tmp/file as content */ private $formData = array (); - // }}} /** The timeout in second before expiring the connection */ private $timeout = 30; + /** Store the user agent. If it is empty, it will not be sent to the server + */ + private $useragent = "HTTPClient"; + // }}} + /** The constructor */ public function __construct () @@ -273,6 +277,20 @@ class Httpclient } // }}} + /** Get / Set the useragent sent to the server. If it is empty, it will not be + * sent + * @param string|null $useragent The user agent to use + */ + public function useragent ($useragent) + // {{{ + { + if ($useragent === null) + return $this->useragent; + $this->useragent = $useragent; + return $this; + } + // }}} + ////////////////////////////////// //// THE ACTIVE METHODS //// ////////////////////////////////// @@ -403,6 +421,8 @@ class Httpclient $this->headersSent[] = "$this->method $path HTTP/1.1"; $this->headersSent[] = "Host: ".$parseURL["host"]; $this->headersSent[] = "Accept: text/html"; + if ($this->useragent !== "") + $this->headersSent[] = "User-Agent: $this->useragent"; $this->headersSent[] = "Connection: keep-alive"; $cookies = $this->cookieToSend ($this->url); if (! empty ($cookies)) @@ -483,7 +503,7 @@ class Httpclient // Get the result header from the server // {{{ $headers = array (); - while (($header = $this->tcpclient->read ()) !== "") + while (($header = $this->tcpclient->read (4095)) !== "") { @list ($key, $val) = explode (":", $header, 2); if ($val === null) @@ -606,7 +626,6 @@ class Httpclient { if ($this->debug < $priority) return; -echo "LOG $this->debug < $priority\n"; if (is_array ($message)) print_r ($message); elseif (is_bool ($message))