Add support of response headers
This commit is contained in:
parent
7b10300713
commit
bbec986c22
@ -57,7 +57,8 @@ class AsyncHttpRequest implements UsageInformationAble {
|
|||||||
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION)// user-agent
|
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION)// user-agent
|
||||||
->set(CURLOPT_RETURNTRANSFER, true)//
|
->set(CURLOPT_RETURNTRANSFER, true)//
|
||||||
->set(CURLOPT_FOLLOWLOCATION, true)// support redirect
|
->set(CURLOPT_FOLLOWLOCATION, true)// support redirect
|
||||||
->set(CURLOPT_SSL_VERIFYPEER, false);
|
->set(CURLOPT_SSL_VERIFYPEER, false)
|
||||||
|
->set(CURLOPT_HEADER, true);
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,8 +122,9 @@ class AsyncHttpRequest implements UsageInformationAble {
|
|||||||
$error = $event->response->getError()->getMessage();
|
$error = $event->response->getError()->getMessage();
|
||||||
} else {
|
} else {
|
||||||
$content = $event->response->getContent();
|
$content = $event->response->getContent();
|
||||||
|
$headers = $event->response->getHeaders();
|
||||||
}
|
}
|
||||||
call_user_func($this->function, $content, $error);
|
call_user_func($this->function, $content, $error, $headers);
|
||||||
});
|
});
|
||||||
|
|
||||||
$fileReader = $this->maniaControl->getFileReader();
|
$fileReader = $this->maniaControl->getFileReader();
|
||||||
|
@ -6,6 +6,7 @@ class Response
|
|||||||
protected $ch;
|
protected $ch;
|
||||||
protected $error;
|
protected $error;
|
||||||
protected $content = null;
|
protected $content = null;
|
||||||
|
protected $headers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs response
|
* Constructs response
|
||||||
@ -17,8 +18,19 @@ class Response
|
|||||||
{
|
{
|
||||||
$this->ch = $request->getHandle();
|
$this->ch = $request->getHandle();
|
||||||
|
|
||||||
if (is_string($content)) {
|
if ($content != null) {
|
||||||
$this->content = $content;
|
$header_size = $this->getInfo(CURLINFO_HEADER_SIZE);
|
||||||
|
|
||||||
|
foreach (explode("\r\n", substr($content, 0, $header_size)) as $value) {
|
||||||
|
if(false !== ($matches = explode(':', $value, 2))) {
|
||||||
|
if (count($matches) === 2) {
|
||||||
|
$headers_arr["{$matches[0]}"] = trim($matches[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->headers = $headers_arr;
|
||||||
|
|
||||||
|
$this->content = substr($content, $header_size);;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,4 +88,14 @@ class Response
|
|||||||
{
|
{
|
||||||
return isset($this->error);
|
return isset($this->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns headers of request
|
||||||
|
*
|
||||||
|
* @return array Headers
|
||||||
|
*/
|
||||||
|
public function getHeaders()
|
||||||
|
{
|
||||||
|
return $this->headers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user