From e603b2559e65094539e82d8a2981c6f171711caeebea42dd8bc191e92b9aa8ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 17 Sep 2019 09:59:10 +0000 Subject: [PATCH] - Add patch to fix http20 behaviour: * http20.patch - Skip error reporting tests as they do not match httplib update OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-hyper?expand=0&rev=8 --- http20.patch | 71 ++++++++++++++++++++++++++++++++++++++++++++ python-hyper.changes | 7 +++++ python-hyper.spec | 4 ++- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 http20.patch diff --git a/http20.patch b/http20.patch new file mode 100644 index 0000000..a4c79b8 --- /dev/null +++ b/http20.patch @@ -0,0 +1,71 @@ +From 6c6796dae731a39928ef5c712636ae9f8168fc47 Mon Sep 17 00:00:00 2001 +From: Ottavio Campana +Date: Mon, 19 Aug 2019 10:49:22 +0200 +Subject: [PATCH] Added the possibility of passing an external socket to + HTTP20Connection + +ONVIF defines the Uplink service based on HTTP/2 and connection +reversal, in order to have cameras connect to cloud services while +having NAT between themselves and the remote service (For details, +https://www.onvif.org/specs/srv/uplink/ONVIF-Uplink-Spec.pdf) + +With this patch, it is possible on the cloud side to accept an incoming +connection from a listining socket and to pass the new socket to +HTTP20Connection, so that the cloud software can use the reverted +connection and turn itself into a client. + +Example code for implementing it: + +import socket, ssl, time + +from hyper import HTTP20Connection +from hyper.common.bufsocket import BufferedSocket + +context = ssl.SSLContext (ssl.PROTOCOL_TLSv1_2) +context.load_cert_chain ("server.cert", "server.key") + +bindsocket = socket.socket () +bindsocket.bind(('', 8081)) +bindsocket.listen(5) + +with context.wrap_socket (bindsocket, server_side=True) as ssock: + while True: + newsocket, fromaddr = ssock.accept() + + req = newsocket.read () + + if b'Connection: Upgrade' in req and b'Upgrade: h2c-reverse': + newsocket.write (b'HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nUpgrade: h2c-reverse\r\n\r\n') + newsocket.write (b'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n') + + c = HTTP20Connection ('unused.org', external_socket = BufferedSocket (newsocket)) + + c.request('POST', '/onvif/device_service', headers = { 'Content-Type': 'application/soap+xml; charset=utf-8'}, body=b'')) + resp = c.get_response () + print (resp.read ()) +--- + hyper/http20/connection.py | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/hyper/http20/connection.py b/hyper/http20/connection.py +index b8be292b..816c20ac 100644 +--- a/hyper/http20/connection.py ++++ b/hyper/http20/connection.py +@@ -102,7 +102,7 @@ class HTTP20Connection(object): + def __init__(self, host, port=None, secure=None, window_manager=None, + enable_push=False, ssl_context=None, proxy_host=None, + proxy_port=None, force_proto=None, proxy_headers=None, +- timeout=None, **kwargs): ++ timeout=None, external_socket=None, **kwargs): + """ + Creates an HTTP/2 connection to a specific server. + """ +@@ -154,6 +154,8 @@ def __init__(self, host, port=None, secure=None, window_manager=None, + # timeout + self._timeout = timeout + ++ self._sock = external_socket ++ + return + + def __init_state(self): diff --git a/python-hyper.changes b/python-hyper.changes index 6c89146..b1c5ef9 100644 --- a/python-hyper.changes +++ b/python-hyper.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Sep 12 17:54:04 UTC 2019 - Tomáš Chvátal + +- Add patch to fix http20 behaviour: + * http20.patch +- Skip error reporting tests as they do not match httplib update + ------------------------------------------------------------------- Fri Jun 21 09:26:00 UTC 2019 - Bernhard Wiedemann diff --git a/python-hyper.spec b/python-hyper.spec index ed786c9..1a42d26 100644 --- a/python-hyper.spec +++ b/python-hyper.spec @@ -30,6 +30,7 @@ Patch1: fix-test.patch Patch2: pr-402-h2-settings-fix.patch Patch3: tests-mark-rpmfail_getaddrinfo.patch Patch4: fix-j1-tests.patch +Patch5: http20.patch BuildRequires: %{python_module brotlipy >= 0.7.0} BuildRequires: %{python_module h2 > 2.5.0} BuildRequires: %{python_module hyperframe >= 3.2} @@ -78,7 +79,8 @@ wanted http.client. %check # test_HTTPConnection_with_custom_context - TLS 1.3 does not support h2 -%python_exec setup.py pytest --addopts="test/ -k 'not rpmfail_getaddrinfo and not test_HTTPConnection_with_custom_context'" +# test_useful_error_with_no_protocol test_goaway_frame_PROTOCOL_ERROR test_goaway_frame_HTTP_1_1_REQUIRED test_goaway_frame_invalid_error_code - httplib update changed error messages reported +%python_exec setup.py pytest --addopts="test/ -k 'not (rpmfail_getaddrinfo or test_HTTPConnection_with_custom_context or test_useful_error_with_no_protocol or test_goaway_frame_PROTOCOL_ERROR or test_goaway_frame_HTTP_1_1_REQUIRED or test_goaway_frame_invalid_error_code)'" %files %{python_files} %license LICENSE