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

Commit

Permalink
Merge pull request #212 from Lukasa/h2
Browse files Browse the repository at this point in the history
Depend on hyper-h2.
  • Loading branch information
Lukasa committed Mar 23, 2016
2 parents 2494811 + fea1359 commit dc20403
Show file tree
Hide file tree
Showing 27 changed files with 675 additions and 3,319 deletions.
11 changes: 11 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
[run]
source = hyper
omit =
hyper/compat.py
hyper/httplib_compat.py
hyper/ssl_compat.py
hyper/packages/*

[report]
fail_under = 100
show_missing = True

[paths]
source =
hyper/
.tox/*/lib/python*/site-packages/hyper
.tox/pypy*/site-packages/hyper
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: python

python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- pypy

env:
Expand Down Expand Up @@ -31,7 +31,8 @@ script:
if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then
py.test test/
else
py.test -n 1 --cov hyper test/
coverage report -m --fail-under 100
coverage run -m py.test test/
coverage combine
coverage report
fi
fi
3 changes: 0 additions & 3 deletions hyper/common/bufsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ def can_read(self):
"""
Whether or not there is more data to read from the socket.
"""
if self._bytes_in_buffer:
return True

read = select.select([self._sck], [], [], 0)[0]
if read:
return True
Expand Down
2 changes: 1 addition & 1 deletion hyper/common/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def replace(self, key, value):
method work like ``__setitem__``. Replacing leads to deletion of all
existing headers with the same name.
"""
key = to_bytestring(key)
key, value = to_bytestring_tuple(key, value)
indices = []
for (i, (k, v)) in enumerate(self._items):
if _keys_equal(k, key):
Expand Down
20 changes: 10 additions & 10 deletions hyper/http11/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from collections import Iterable, Mapping

from hyperframe.frame import SettingsFrame

from .response import HTTP11Response
from ..tls import wrap_socket, H2C_PROTOCOL
from ..common.bufsocket import BufferedSocket
Expand All @@ -20,8 +22,6 @@
from ..common.util import to_bytestring, to_host_port_tuple
from ..compat import bytes

from ..packages.hyperframe.frame import SettingsFrame

# We prefer pycohttpparser to the pure-Python interpretation
try: # pragma: no cover
from pycohttpparser.api import Parser
Expand Down Expand Up @@ -49,13 +49,13 @@ class HTTP11Connection(object):
port 443.
:param ssl_context: (optional) A class with custom certificate settings.
If not provided then hyper's default ``SSLContext`` is used instead.
:param proxy_host: (optional) The proxy to connect to. This can be an IP
:param proxy_host: (optional) The proxy to connect to. This can be an IP
address or a host name and may include a port.
:param proxy_port: (optional) The proxy port to connect to. If not provided
and one also isn't provided in the ``proxy`` parameter,
:param proxy_port: (optional) The proxy port to connect to. If not provided
and one also isn't provided in the ``proxy`` parameter,
defaults to 8080.
"""
def __init__(self, host, port=None, secure=None, ssl_context=None,
def __init__(self, host, port=None, secure=None, ssl_context=None,
proxy_host=None, proxy_port=None, **kwargs):
if port is None:
self.host, self.port = to_host_port_tuple(host, default_port=80)
Expand Down Expand Up @@ -112,7 +112,7 @@ def connect(self):
else:
host = self.proxy_host
port = self.proxy_port

sock = socket.create_connection((host, port), 5)
proto = None

Expand Down Expand Up @@ -200,8 +200,8 @@ def get_response(self):

self._sock.advance_buffer(response.consumed)

if (response.status == 101 and
b'upgrade' in headers['connection'] and
if (response.status == 101 and
b'upgrade' in headers['connection'] and
H2C_PROTOCOL.encode('utf-8') in headers['upgrade']):
raise HTTPUpgrade(H2C_PROTOCOL, self._sock)

Expand Down Expand Up @@ -260,7 +260,7 @@ def _add_upgrade_headers(self, headers):
# Add HTTP Upgrade headers.
headers[b'connection'] = b'Upgrade, HTTP2-Settings'
headers[b'upgrade'] = H2C_PROTOCOL

# Encode SETTINGS frame payload in Base64 and put into the HTTP-2 Settings header.
http2_settings = SettingsFrame(0)
http2_settings.settings[SettingsFrame.INITIAL_WINDOW_SIZE] = 65535
Expand Down

0 comments on commit dc20403

Please sign in to comment.