[WebSocket] Refactor

Fixing bugs in hixieeeeeeee
This commit is contained in:
Mike Almond 2012-02-08 13:19:42 -05:00
parent c6a801f1ef
commit f6fef1a390
3 changed files with 21 additions and 28 deletions

View File

@ -34,7 +34,10 @@ class Hixie76 implements VersionInterface {
, 'Sec-WebSocket-Location' => 'ws://' . $request->getHeader('Host') . $request->getPath()
);
return new \Guzzle\Http\Message\Response('101', $headers, $body);
$response = new \Guzzle\Http\Message\Response('101', $headers, $body);
$response->setStatus('101', 'WebSocket Protocol Handshake');
return $response;
}
public function newMessage() {

View File

@ -41,11 +41,7 @@ class RFC6455 implements VersionInterface {
, 'Sec-WebSocket-Accept' => $this->sign($request->getHeader('Sec-WebSocket-Key'))
);
$response = new \Guzzle\Http\Message\Response(101, $headers);
return $response;
return new \Guzzle\Http\Message\Response('101', $headers);
}
/**

View File

@ -79,23 +79,17 @@ class WebSocketComponent implements MessageComponentInterface {
$response = $from->WebSocket->version->handshake($from->WebSocket->headers);
$from->WebSocket->handshake = true;
// This block is to be moved/changed later
$agreed_protocols = array();
$requested_protocols = $from->WebSocket->headers->getTokenizedHeader('Sec-WebSocket-Protocol', ',');
foreach ($this->accepted_subprotocols as $sub_protocol) {
if (false !== $requested_protocols->hasValue($sub_protocol)) {
if (null !== $requested_protocols && false !== $requested_protocols->hasValue($sub_protocol)) {
$agreed_protocols[] = $sub_protocol;
}
}
if (count($agreed_protocols) > 0) {
// $response['Sec-WebSocket-Protocol'] = implode(',', $agreed_protocols);
$response->setHeader('Sec-WebSocket-Protocol', implode(',', $agreed_protocols));
}
$header = (string)$response;