46 lines
928 B
PHP
46 lines
928 B
PHP
<?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'];
|
|
}
|
|
|
|
}
|
|
|