This repository was archived by the owner on Jan 13, 2021. It is now read-only.
Added the possibility of passing an external socket to HTTP20Connection#418
Open
ocampana wants to merge 1 commit intopython-hyper:developmentfrom
Open
Added the possibility of passing an external socket to HTTP20Connection#418ocampana wants to merge 1 commit intopython-hyper:developmentfrom
ocampana wants to merge 1 commit intopython-hyper:developmentfrom
Conversation
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'<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"><soap:Body><tds:GetDeviceInformation /></soap:Body></soap:Envelope>')) resp = c.get_response () print (resp.read ())
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: