Comments (9)
On how to get the data, see the existing unittest for upgrade. Although I think I'll remove the exception in favour of a callback, as you suggested.
from httptools.
i think there is bug in offset calculation
import httptools
import unittest
from unittest import mock
UPGRADE_RESPONSE = b'''HTTP/1.1 101 Switching Protocols\r\nUPGRADE: websocket\r\nSEC-WEBSOCKET-ACCEPT: rVg+XakFNFOxk3ZH0lzrZBmg0aU=\r\nTRANSFER-ENCODING: chunked\r\nCONNECTION: upgrade\r\nDATE: Sat, 07 May 2016 23:44:32 GMT\r\nSERVER: Python/3.4 aiohttp/1.0.3\r\n\r\n\x89\x04data'''
class TestResponseParser(unittest.TestCase):
def test_parser_upgrade_response(self):
m = mock.Mock()
headers = {}
m.on_header.side_effect = headers.__setitem__
p = httptools.HttpResponseParser(m)
try:
p.feed_data(UPGRADE_RESPONSE)
except httptools.HttpParserUpgrade as ex:
offset = ex.args[0]
else:
self.fail('HttpParserUpgrade was not raised')
self.assertEqual(UPGRADE_RESPONSE[offset:], b'\x89\x04data')
self.assertEqual(p.get_http_version(), '1.1')
self.assertEqual(p.get_status_code(), 101)
m.on_status.assert_called_once_with(b'Switching Protocols')
m.on_headers_complete.assert_called_once_with()
self.assertEqual(m.on_header.call_count, 6)
self.assertEqual(len(headers), 6)
m.on_message_complete.assert_called_once_with()
got this AssertionError: b'\x04data' != b'\x89\x04data'
from httptools.
Transfer encoding is set to chunked
. If I remove the transfer-encoding
header everything works as expected.
from httptools.
Are you sure that this response is valid?
from httptools.
i am not sure, but autobahn
test suit passes for default websocket implementation.
from httptools.
Is this response something that autobahn tests for?
To me this seems like an invalid response -- you essentially ask the protocol to upgrade, at the same time specifying the transfer-encoding. If this is a real-world situation then we probably need to fix http-parser.c
from httptools.
Alright, seems that http-parser supports this -- have to fix the httptools. Working on it.
from httptools.
Should be fixed in v0.0.9
from httptools.
thanks, works!
from httptools.
Related Issues (20)
- 0.1.0 does not support Python 3.5 HOT 1
- API change from 0.0.13->0.1.1 HOT 2
- Deprecation warnings in Python 3.10 HOT 3
- Wheel support for linux aarch64 HOT 1
- provide wheel for python3.9 HOT 9
- Note: httptools 0.0.13 from PyPI is incompatible with Python 3.9
- PROXY protocol v1 / v2 support
- [Security] Potential Secret Leak HOT 1
- Silent fail of long url parsing HOT 2
- Git release/tag for 0.2.0 pypi version HOT 2
- Wheels for httptools 0.2.0 on Python 3.10 HOT 1
- CVE-2021-22959 & CVE-2021-22960
- Doesn't build against Python 3.11 HOT 3
- Fail to get wheel for python 3.9.5 when pip install
- llhttp critical CVE's HOT 4
- How to do an early stop? HOT 2
- . HOT 1
- with curl and https HOT 1
- Error installing httptools as a uvicorn dependency HOT 2
- Create wheel for Python 3.12 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httptools.