Initial commit
This commit is contained in:
45
src/HTTPU/Response.php
Normal file
45
src/HTTPU/Response.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\UPnP\HTTPU;
|
||||
|
||||
class Response
|
||||
{
|
||||
protected $headers = [];
|
||||
|
||||
protected $ip;
|
||||
|
||||
public function __construct(array $headers, $ip)
|
||||
{
|
||||
$this->headers = $headers;
|
||||
$this->ip = $ip;
|
||||
}
|
||||
|
||||
public static function createFromString($string, $ip)
|
||||
{
|
||||
$data = explode("\r\n", trim($string));
|
||||
$status = array_shift($data);
|
||||
$headers = [];
|
||||
foreach ($data as $line) {
|
||||
list ($header, $value) = array_map("trim", explode(":",$line,2));
|
||||
$headers[strtolower($header)] = $value;
|
||||
}
|
||||
|
||||
// Test for search responses using the ST header
|
||||
if (array_key_exists('st', $headers)) {
|
||||
return new MSearchResponse($headers, $ip);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getIp()
|
||||
{
|
||||
return $this->ip;
|
||||
}
|
||||
|
||||
public function getLocation()
|
||||
{
|
||||
return $this->headers['location'];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user