Skip to content

Commit

Permalink
Merge pull request #68 from WarriorXK/release/3.1.0
Browse files Browse the repository at this point in the history
Release/3.1.0
  • Loading branch information
WarriorXK authored Feb 23, 2021
2 parents 78e8707 + 22e30b1 commit 3bb00d5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cache:
php:
- 7.3
- 7.4
- 8.0
- nightly

env:
Expand All @@ -18,8 +19,8 @@ env:

matrix:
fast_finish: true
# allow_failures:
# - php: nightly
allow_failures:
- php: nightly

before_script:
- sudo apt-get update
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# PHPWebSockets
[![Code documented](https://codedocs.xyz/WarriorXK/PHPWebSockets.svg)](https://codedocs.xyz/WarriorXK/PHPWebSockets/) Master: [![Build Status](https://travis-ci.com/WarriorXK/PHPWebSockets.svg?branch=master)](https://travis-ci.com/WarriorXK/PHPWebSockets) Develop: [![Build Status](https://travis-ci.com/WarriorXK/PHPWebSockets.svg?branch=develop)](https://travis-ci.com/WarriorXK/PHPWebSockets)

A PHP 7.0+ library to accept and create websocket connections, we aim to be 100% compliant with the websocket RFC and use the [Autobahn test suite](http://autobahn.ws/testsuite/) to ensure so.
A PHP library to accept and create websocket connections, we aim to be 100% compliant with the websocket RFC and use the [Autobahn test suite](http://autobahn.ws/testsuite/) to ensure so.
Currently the server and the client are 100% compliant with the autobahn testsuite minus a few non-strict notices, the [compression extension](https://tools.ietf.org/html/rfc7692) for websockets will be implemented later

## Server
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1
3.1.0
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "warriorxk/phpwebsockets",
"type": "library",
"description": "A websocket library for PHP 7.0+ with support for IPC using socket pairs",
"description": "A websocket library with support for IPC using socket pairs",
"keywords": ["websocket", "php", "phpwebsockets", "ipc", "socket", "client", "server"],
"homepage": "https://github.com/WarriorXK/PHPWebSockets",
"license": "MIT",
Expand Down
21 changes: 16 additions & 5 deletions src/PHPWebSockets/Server/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,22 +305,33 @@ protected function _parseHeaders() : void {
/**
* Accepts the connection
*
* @param string|null $protocol The accepted protocol
* @param string|null $protocol The accepted protocol
* @param string[] $additionalHeaders Additional headers to send in the response
*
* @return void
*/
public function accept(string $protocol = NULL) : void {
public function accept(string $protocol = NULL, array $additionalHeaders = []) : void {

if ($this->isAccepted()) {
throw new \LogicException('Connection has already been accepted!');
}

$misc = '';
$headers = [
'Server: ' . $this->_server->getServerIdentifier(),
'Upgrade: websocket',
'Connection: Upgrade',
'Sec-WebSocket-Accept: ' . base64_encode($this->_rawToken),
];

if ($protocol !== NULL) {
$misc .= 'Sec-WebSocket-Protocol ' . $protocol . "\r\n";
$headers[] = 'Sec-WebSocket-Protocol: ' . $protocol;
}

foreach ($additionalHeaders as $header) {
$headers[] = $header;
}

$this->writeRaw('HTTP/1.1 101 ' . \PHPWebSockets::GetStringForStatusCode(101) . "\r\nServer: " . $this->_server->getServerIdentifier() . "\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: " . base64_encode($this->_rawToken) . "\r\n" . $misc . "\r\n", FALSE);
$this->writeRaw('HTTP/1.1 101 ' . \PHPWebSockets::GetStringForStatusCode(101) . "\r\n" . implode("\r\n", $headers) . "\r\n\r\n", FALSE);

$this->_accepted = TRUE;

Expand Down

0 comments on commit 3bb00d5

Please sign in to comment.