httpclient : allow 3 modes : Chunked, Content-Length and connection closed modes
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4807 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -378,6 +378,7 @@ class Httpclient
|
||||
return $this;
|
||||
}
|
||||
// }}}
|
||||
|
||||
//////////////////////////////////
|
||||
//// THE ACTIVE METHODS ////
|
||||
//////////////////////////////////
|
||||
@@ -523,7 +524,7 @@ class Httpclient
|
||||
$cookies = $this->cookieToSend ($this->url);
|
||||
if (! empty ($cookies))
|
||||
{
|
||||
$this->headersSent[] = "Cookie: ".implode (";", $cookies);
|
||||
$this->headersSent[] = "Cookie: ".implode ("; ", $cookies);
|
||||
}
|
||||
if ($this->method !== "GET" && ! empty ($this->formData))
|
||||
{
|
||||
@@ -597,7 +598,7 @@ class Httpclient
|
||||
// }}}
|
||||
|
||||
// Get the result header from the server
|
||||
// {{{
|
||||
// {{{
|
||||
$headers = array ();
|
||||
while (($header = $this->tcpclient->read (4095)) !== "")
|
||||
{
|
||||
@@ -666,15 +667,19 @@ class Httpclient
|
||||
}
|
||||
if ($this->contentMethod === "chunked")
|
||||
$this->log (1, "URL $this->method $this->url $this->httpCode Chunked");
|
||||
elseif (is_int ($this->bodySize))
|
||||
$this->log (1, "URL $this->method $this->url $this->httpCode ".
|
||||
$this->bodySize);
|
||||
else
|
||||
$this->log (1, "URL $this->method $this->url $this->httpCode $this->bodySize");
|
||||
|
||||
$this->log (1, "URL $this->method $this->url $this->httpCode 0");
|
||||
// }}}
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Read max MAXSIZE bytes
|
||||
* Return false if all the file is received
|
||||
* Return "" if all the file is received
|
||||
* 3 methods are supported : Chunked mode, Content-Length defined and all
|
||||
* until the connection will be closed by the server
|
||||
* @param integer $maxsize The maxsize to get in this read
|
||||
*/
|
||||
public function read ($maxsize = 4096)
|
||||
@@ -683,12 +688,12 @@ class Httpclient
|
||||
if ($this->tcpclient === null)
|
||||
throw new \Exception ("HTTPClient : can not read non connected URL", 406);
|
||||
$this->tcpclient->timeout ($this->timeout);
|
||||
if ($this->contentMethod === false)
|
||||
/* if ($this->contentMethod === false)
|
||||
{
|
||||
// If the server will never send anything, code 204 by example, do not try
|
||||
// to get data
|
||||
return "";
|
||||
}
|
||||
}*/
|
||||
$content = "";
|
||||
if ($this->contentMethod === "chunked" && $this->bodySize === 0)
|
||||
{
|
||||
@@ -699,13 +704,17 @@ class Httpclient
|
||||
}
|
||||
if ($this->bodySize === 0)
|
||||
return "";
|
||||
|
||||
$toBeRead = $this->bodySize;
|
||||
if ($this->bodySize === null)
|
||||
$toBeRead = $maxsize;
|
||||
else
|
||||
$toBeRead = $this->bodySize;
|
||||
if ($toBeRead > $maxsize)
|
||||
$toBeRead = $maxsize;
|
||||
$this->tcpclient->readMode ("binary");
|
||||
$content = $this->tcpclient->read ($toBeRead);
|
||||
$this->bodySize = $this->bodySize - strlen ($content);
|
||||
// In close mode, the bodySize is not set and should not be updated
|
||||
if ($this->bodySize !== null)
|
||||
$this->bodySize = $this->bodySize - strlen ($content);
|
||||
if ($this->contentMethod === "chunked" && $this->bodySize === 0)
|
||||
{
|
||||
// Get the Carriage return before the next chunk size
|
||||
|
||||
Reference in New Issue
Block a user