1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-04 02:09:23 +02:00

Begin WebSocket support for Broadcast and Player control

This commit is contained in:
Afterster 2014-02-05 08:08:46 +01:00
parent 2b128b122d
commit 6adf8307c4
516 changed files with 64260 additions and 18 deletions

View file

@ -0,0 +1,81 @@
<?php
namespace React\HttpClient;
class RequestData
{
private $method;
private $url;
private $headers;
private $protocolVersion = '1.1';
public function __construct($method, $url, array $headers = array())
{
$this->method = $method;
$this->url = $url;
$this->headers = $headers;
}
private function mergeDefaultheaders(array $headers)
{
$port = ($this->getDefaultPort() === $this->getPort()) ? '' : ":{$this->getPort()}";
$connectionHeaders = ('1.1' === $this->protocolVersion) ? array('Connection' => 'close') : array();
return array_merge(
array(
'Host' => $this->getHost().$port,
'User-Agent' => 'React/alpha',
),
$connectionHeaders,
$headers
);
}
public function getScheme()
{
return parse_url($this->url, PHP_URL_SCHEME);
}
public function getHost()
{
return parse_url($this->url, PHP_URL_HOST);
}
public function getPort()
{
return (int) parse_url($this->url, PHP_URL_PORT) ?: $this->getDefaultPort();
}
public function getDefaultPort()
{
return ('https' === $this->getScheme()) ? 443 : 80;
}
public function getPath()
{
$path = parse_url($this->url, PHP_URL_PATH) ?: '/';
$queryString = parse_url($this->url, PHP_URL_QUERY);
return $path.($queryString ? "?$queryString" : '');
}
public function setProtocolVersion($version)
{
$this->protocolVersion = $version;
}
public function __toString()
{
$headers = $this->mergeDefaultheaders($this->headers);
$data = '';
$data .= "{$this->method} {$this->getPath()} HTTP/{$this->protocolVersion}\r\n";
foreach ($headers as $name => $value) {
$data .= "$name: $value\r\n";
}
$data .= "\r\n";
return $data;
}
}