This commit is contained in:
Maximilian Hils
2016-02-27 02:17:10 +01:00
5 changed files with 19 additions and 17 deletions

View File

@@ -13,8 +13,8 @@ environment:
SNAPSHOT_PASS: SNAPSHOT_PASS:
secure: LPjrtFrWxYhOVGXzfPRV1GjtZE/wHoKq9m/PI6hSalfysUK5p2DxTG9uHlb4Q9qV secure: LPjrtFrWxYhOVGXzfPRV1GjtZE/wHoKq9m/PI6hSalfysUK5p2DxTG9uHlb4Q9qV
install: install:
- "pip install --user -U pip setuptools" - "pip install --user -U virtualenv"
- "pip install --user -r requirements.txt" - "dev.bat"
- "python -c \"from OpenSSL import SSL; print(SSL.SSLeay_version(SSL.SSLEAY_VERSION))\"" - "python -c \"from OpenSSL import SSL; print(SSL.SSLeay_version(SSL.SSLEAY_VERSION))\""
test_script: test_script:
- "py.test" - "py.test"

View File

@@ -37,11 +37,13 @@ install:
brew outdated openssl || brew upgrade openssl brew outdated openssl || brew upgrade openssl
brew install python brew install python
fi fi
- "pip install -U pip setuptools" - pip install -U virtualenv
- "pip install -r requirements.txt" - ./dev.sh
- source ./venv/bin/activate
before_script: before_script:
- "openssl version -a" - "openssl version -a"
- "python -c \"from OpenSSL import SSL; print(SSL.SSLeay_version(SSL.SSLEAY_VERSION))\""
script: script:
- "py.test ./test/$SCOPE" - "py.test ./test/$SCOPE"

View File

@@ -12,4 +12,3 @@ echo.
echo * Created virtualenv environment in %VENV%. echo * Created virtualenv environment in %VENV%.
echo * Installed all dependencies into the virtualenv. echo * Installed all dependencies into the virtualenv.
echo * Activated virtualenv environment. echo * Activated virtualenv environment.
pause

1
dev.sh
View File

@@ -4,6 +4,7 @@ VENV=./venv
python -m virtualenv $VENV --always-copy python -m virtualenv $VENV --always-copy
. $VENV/bin/activate . $VENV/bin/activate
pip install -U pip setuptools
pip install -r requirements.txt pip install -r requirements.txt
echo "" echo ""

View File

@@ -4,14 +4,14 @@ import threading
import time import time
import Queue import Queue
import h2
from h2.connection import H2Connection
from netlib.tcp import ssl_read_select from netlib.tcp import ssl_read_select
from netlib.exceptions import HttpException from netlib.exceptions import HttpException
from netlib.http import Headers from netlib.http import Headers
from netlib.utils import http2_read_raw_frame from netlib.utils import http2_read_raw_frame
from h2.connection import H2Connection
from h2.events import *
from .base import Layer from .base import Layer
from .http import _HttpTransmissionLayer, HttpLayer from .http import _HttpTransmissionLayer, HttpLayer
from .. import utils from .. import utils
@@ -139,27 +139,27 @@ class Http2Layer(Layer):
else: else:
eid = event.stream_id eid = event.stream_id
if isinstance(event, RequestReceived): if isinstance(event, h2.events.RequestReceived):
headers = Headers([[str(k), str(v)] for k, v in event.headers]) headers = Headers([[str(k), str(v)] for k, v in event.headers])
self.streams[eid] = Http2SingleStreamLayer(self, eid, headers) self.streams[eid] = Http2SingleStreamLayer(self, eid, headers)
self.streams[eid].timestamp_start = time.time() self.streams[eid].timestamp_start = time.time()
self.streams[eid].start() self.streams[eid].start()
elif isinstance(event, ResponseReceived): elif isinstance(event, h2.events.ResponseReceived):
headers = Headers([[str(k), str(v)] for k, v in event.headers]) headers = Headers([[str(k), str(v)] for k, v in event.headers])
self.streams[eid].queued_data_length = 0 self.streams[eid].queued_data_length = 0
self.streams[eid].timestamp_start = time.time() self.streams[eid].timestamp_start = time.time()
self.streams[eid].response_headers = headers self.streams[eid].response_headers = headers
self.streams[eid].response_arrived.set() self.streams[eid].response_arrived.set()
elif isinstance(event, DataReceived): elif isinstance(event, h2.events.DataReceived):
if self.config.body_size_limit and self.streams[eid].queued_data_length > self.config.body_size_limit: if self.config.body_size_limit and self.streams[eid].queued_data_length > self.config.body_size_limit:
raise HttpException("HTTP body too large. Limit is {}.".format(self.config.body_size_limit)) raise HttpException("HTTP body too large. Limit is {}.".format(self.config.body_size_limit))
self.streams[eid].data_queue.put(event.data) self.streams[eid].data_queue.put(event.data)
self.streams[eid].queued_data_length += len(event.data) self.streams[eid].queued_data_length += len(event.data)
source_conn.h2.safe_increment_flow_control(event.stream_id, event.flow_controlled_length) source_conn.h2.safe_increment_flow_control(event.stream_id, event.flow_controlled_length)
elif isinstance(event, StreamEnded): elif isinstance(event, h2.events.StreamEnded):
self.streams[eid].timestamp_end = time.time() self.streams[eid].timestamp_end = time.time()
self.streams[eid].data_finished.set() self.streams[eid].data_finished.set()
elif isinstance(event, StreamReset): elif isinstance(event, h2.events.StreamReset):
self.streams[eid].zombie = time.time() self.streams[eid].zombie = time.time()
self.client_reset_streams.append(self.streams[eid].client_stream_id) self.client_reset_streams.append(self.streams[eid].client_stream_id)
if self.streams[eid].server_stream_id: if self.streams[eid].server_stream_id:
@@ -171,14 +171,14 @@ class Http2Layer(Layer):
other_stream_id = self.streams[eid].server_stream_id other_stream_id = self.streams[eid].server_stream_id
if other_stream_id is not None: if other_stream_id is not None:
other_conn.h2.safe_reset_stream(other_stream_id, event.error_code) other_conn.h2.safe_reset_stream(other_stream_id, event.error_code)
elif isinstance(event, RemoteSettingsChanged): elif isinstance(event, h2.events.RemoteSettingsChanged):
new_settings = dict([(id, cs.new_value) for (id, cs) in event.changed_settings.iteritems()]) new_settings = dict([(id, cs.new_value) for (id, cs) in event.changed_settings.iteritems()])
other_conn.h2.safe_update_settings(new_settings) other_conn.h2.safe_update_settings(new_settings)
elif isinstance(event, ConnectionTerminated): elif isinstance(event, h2.events.ConnectionTerminated):
# Do not immediately terminate the other connection. # Do not immediately terminate the other connection.
# Some streams might be still sending data to the client. # Some streams might be still sending data to the client.
return False return False
elif isinstance(event, PushedStreamReceived): elif isinstance(event, h2.events.PushedStreamReceived):
# pushed stream ids should be uniq and not dependent on race conditions # pushed stream ids should be uniq and not dependent on race conditions
# only the parent stream id must be looked up first # only the parent stream id must be looked up first
parent_eid = self.server_to_client_stream_ids[event.parent_stream_id] parent_eid = self.server_to_client_stream_ids[event.parent_stream_id]
@@ -194,7 +194,7 @@ class Http2Layer(Layer):
self.streams[event.pushed_stream_id].timestamp_end = time.time() self.streams[event.pushed_stream_id].timestamp_end = time.time()
self.streams[event.pushed_stream_id].request_data_finished.set() self.streams[event.pushed_stream_id].request_data_finished.set()
self.streams[event.pushed_stream_id].start() self.streams[event.pushed_stream_id].start()
elif isinstance(event, TrailersReceived): elif isinstance(event, h2.events.TrailersReceived):
raise NotImplementedError() raise NotImplementedError()
return True return True