Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket Upgrade header should not be case sensitive #969

Closed
1 task done
dermotduffy opened this issue Aug 16, 2020 · 2 comments · Fixed by #1036
Closed
1 task done

Websocket Upgrade header should not be case sensitive #969

dermotduffy opened this issue Aug 16, 2020 · 2 comments · Fixed by #1036

Comments

@dermotduffy
Copy link
Contributor

  • I confirm that this is an issue rather than a question.

Bug report

In playing with Python websocket connections to Hyperion, I ran into a problem: the connection was not properly being upgraded to a websocket:

Steps to reproduce

Run this, changing hyperion:8090 to a Hyperion host:

#!/usr/bin/python3

import aiohttp
import asyncio

async def routine():
  session = aiohttp.ClientSession()
  async with session.ws_connect('http://hyperion:8090') as ws:
    pass
  await session.close()
asyncio.get_event_loop().run_until_complete(routine())

The same code will execute cleanly with this connection code:

  async with session.ws_connect('http://hyperion:8090', headers={'Upgrade':'websocket'}) as ws:

This is caused by libsrc/webserver/QtHttpClientWrapper.cpp:

156           if(m_currentRequest->getHeader(QtHttpHeader::Upgrade) == "websocket")

Note the case sensitive comparison, which is inappropriate in this situation:

   An |Upgrade| header field containing the value "websocket",
        treated as an ASCII case-insensitive value.

What is expected?

It should exit cleanly.

What is actually happening?

Traceback (most recent call last):
  File "./ws.py", line 11, in <module>
    asyncio.get_event_loop().run_until_complete(routine())
  File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
    return future.result()
  File "./ws.py", line 8, in routine
    async with session.ws_connect('http://hyperion:8090') as ws:
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/client.py", line 738, in _ws_connect
    headers=resp.headers)
aiohttp.client_exceptions.WSServerHandshakeError: 200, message='Invalid response status', url=URL('http://hyperion:8090')
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f994f4e4e80>

System

Hyperion Server: 
- Build:       master (GitHub-f719f0b/838092e-1597257777)
- Build time:  Aug 15 2020 04:03:20
- Git Remote:  https://github.com/hyperion-project/hyperion.ng.git
- Version:     2.0.0-alpha.7
- UI Lang:     auto (BrowserLang: en-US)
- UI Access:   default
- Avail Capt:  dispmanx,v4l2,framebuffer,qt

Hyperion Server OS: 
- Distribution: Raspbian GNU/Linux 10 (buster)
- Arch:         arm
- Kernel:       linux (5.4.51+ (WS: 32))
- Browser:      Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/53
Paulchen-Panther added a commit to Paulchen-Panther/hyperion.ng that referenced this issue Oct 8, 2020
@Paulchen-Panther
Copy link
Member

Fixed in PR #1036

@dermotduffy
Copy link
Contributor Author

@Paulchen-Panther Thank you, verified!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants