Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 71d4a3b

Browse files
committed
Add pycohttpparser support.
1 parent a134cfe commit 71d4a3b

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010
- TEST_RELEASE=false
1111
- TEST_RELEASE=true
1212
- NGHTTP2=true
13+
- HYPER_FAST_PARSE=true
1314

1415
matrix:
1516
allow_failures:

.travis/install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,9 @@ if [[ "$NGHTTP2" = true ]]; then
3939
sudo ldconfig
4040
fi
4141

42+
if [[ "$HYPER_FAST_PARSE" = true ]]; then
43+
pip install pycohttpparser~=1.0
44+
fi
45+
4246
pip install .
4347
pip install -r test_requirements.txt

hyper/http11/connection.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
import socket
1111

1212
from .response import HTTP11Response
13-
from .parser import Parser
1413
from ..tls import wrap_socket, H2_NPN_PROTOCOLS
1514
from ..http20.bufsocket import BufferedSocket
1615
from ..common.headers import HTTPHeaderMap
1716
from ..common.util import to_bytestring
1817
from ..compat import bytes
1918

19+
20+
# We prefer pycohttpparser to the pure-Python interpretation
21+
try: # pragma: no cover
22+
from pycohttpparser.api import Parser
23+
except ImportError: # pragma: no cover
24+
from .parser import Parser
25+
26+
2027
log = logging.getLogger(__name__)
2128

2229
BODY_CHUNKED = 1

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,7 @@ def resolve_install_requires():
6868
'hyper = hyper.cli:main',
6969
],
7070
},
71+
extras_require={
72+
'fast': ['pycohttpparser~=1.0'],
73+
}
7174
)

test/test_http11.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@
1818

1919

2020
class TestHTTP11Connection(object):
21+
def test_pycohttpparser_installs_correctly(self):
22+
# This test is a debugging tool: if pycohttpparser is being tested by
23+
# Travis, we need to confirm it imports correctly. Hyper will normally
24+
# hide the import failure, so let's discover it here.
25+
# Alternatively, if we are *not* testing with nghttp2, this test should
26+
# confirm that it's not available.
27+
if os.environ.get('HYPER_FAST_PARSE'):
28+
import pycohttpparser
29+
else:
30+
with pytest.raises(ImportError):
31+
import pycohttpparser
32+
33+
assert True
34+
2135
def test_initialization_no_port(self):
2236
c = HTTP11Connection('http2bin.org')
2337

0 commit comments

Comments
 (0)