Библиотека для cis, online, cms1
This commit is contained in:
commit
3c2e614d87
269 changed files with 39854 additions and 0 deletions
82
core/connection/httpconnectionresponse.php
Normal file
82
core/connection/httpconnectionresponse.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Îáðàáàòûâàåò HTTP îòâåò
|
||||
*/
|
||||
class HttpConnectionResponse
|
||||
{
|
||||
private $offset;
|
||||
private $param = array ();
|
||||
private $code;
|
||||
|
||||
public function __construct($response)
|
||||
{
|
||||
$this->offset = 0;
|
||||
$this->response = $response;
|
||||
$this->parseMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Îáðàáîòêà HTTP îòâåòà
|
||||
*/
|
||||
private function parseMessage()
|
||||
{
|
||||
$http = explode(" ", $this->getLine());
|
||||
$this->version = $http[0];
|
||||
$this->code = $http[1];
|
||||
|
||||
$line = $this->getLine();
|
||||
while ($offset = strpos($line, ":")) {
|
||||
$this->param[substr($line, 0, $offset)] = trim(substr($line, $offset + 1));
|
||||
$line = $this->getLine();
|
||||
}
|
||||
|
||||
if (isset($this->param['Transfer-Encoding']) && $this->param['Transfer-Encoding'] == 'chunked') {
|
||||
//$this->data = substr($this->response, $this->offset);
|
||||
$line = hexdec($this->getLine());
|
||||
$chunk = array();
|
||||
while ($line > 0) {
|
||||
$chunk [] = substr($this->response, $this->offset, $line);
|
||||
$this->offset += $line;
|
||||
$line = hexdec($this->getLine());
|
||||
}
|
||||
|
||||
$this->data = implode("", $chunk);
|
||||
} else {
|
||||
$this->data = substr($this->response, $this->offset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Îáðàáîòêà ñòðîêè HTTP îòâåòà
|
||||
*/
|
||||
private function getLine()
|
||||
{
|
||||
$begin = $this->offset;
|
||||
$offset = strpos($this->response, "\r\n", $this->offset);
|
||||
$result = substr($this->response, $begin, $offset - $begin);
|
||||
$this->offset = $offset + 2;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Çíà÷åíèå ïàðàìåòðà HTTP îòâåòà
|
||||
*/
|
||||
public function getParameter($name)
|
||||
{
|
||||
return $this->param[$name];
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ñîñòîÿíèå
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue