From 7ed72dc4b7e777a8910419bd4a5fd4c3c5706d52 Mon Sep 17 00:00:00 2001 From: Matt Bonneau Date: Fri, 29 Jul 2016 01:27:59 -0400 Subject: [PATCH] Explode `Connection:` header to find `Update`. Fixes #14 --- src/Handshake/RequestVerifier.php | 15 ++++++++++++--- tests/unit/Handshake/RequestVerifierTest.php | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Handshake/RequestVerifier.php b/src/Handshake/RequestVerifier.php index aa6a419..1ace489 100644 --- a/src/Handshake/RequestVerifier.php +++ b/src/Handshake/RequestVerifier.php @@ -92,9 +92,18 @@ class RequestVerifier { * @return bool */ public function verifyConnection(array $connectionHeader) { - return count(array_filter($connectionHeader, function ($x) { - return 'upgrade' === strtolower($x); - })) > 0; + foreach ($connectionHeader as $l) { + $upgrades = array_filter( + array_map('trim', array_map('strtolower', explode(',', $l))), + function ($x) { + return 'upgrade' === $x; + } + ); + if (count($upgrades) > 0) { + return true; + } + } + return false; } /** diff --git a/tests/unit/Handshake/RequestVerifierTest.php b/tests/unit/Handshake/RequestVerifierTest.php index e0569fd..239de33 100644 --- a/tests/unit/Handshake/RequestVerifierTest.php +++ b/tests/unit/Handshake/RequestVerifierTest.php @@ -113,6 +113,11 @@ class RequestVerifierTest extends \PHPUnit_Framework_TestCase { array(true, ['keep-alive', 'Upgrade']), array(true, ['Upgrade', 'keep-alive']), array(true, ['keep-alive', 'Upgrade', 'something']), + // as seen in Firefox 47.0.1 - see https://github.com/ratchetphp/RFC6455/issues/14 + array(true, ['keep-alive, Upgrade']), + array(true, ['Upgrade, keep-alive']), + array(true, ['keep-alive, Upgrade, something']), + array(true, ['keep-alive, Upgrade', 'something']), array(false, ['']), array(false, []) );