httpclient : set a default User-Agent and allow to set it to anything
httpclient : each header line is now set to 4065 chars max (1024 was too short in case of cookies or SAML authentication) git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4798 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user