Python hyper.HTTP20Connection() Examples

The following are 9 code examples of hyper.HTTP20Connection(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module hyper , or try the search function .
Example #1
Source File: client.py    From python-apns with MIT License 5 votes vote down vote up
def _create_connection(self):
        return HTTP20Connection(self.host, force_proto=self.force_proto) 
Example #2
Source File: transport.py    From linepy-modified with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def open(self):
        if self.request == 'hyper':
            if self.http2:
                self.__http = hyper.HTTP20Connection(self.host, self.port, proxy_host=self.realhost, proxy_port=self.realport, proxy_headers=self.proxy_headers)
            else:
                self.__http = hyper.HTTPConnection(self.host, self.port, proxy_host=self.realhost, proxy_port=self.realport, proxy_headers=self.proxy_headers)
        elif self.request == 'httpx':
            if self.http2:
                self.__http = httpx.AsyncClient(base_url='%s://%s' % (self.scheme, self.host), http2=self.http2)
            else:
                self.__http = httpx.Client(base_url='%s://%s' % (self.scheme, self.host))
        elif self.request == 'requests':
            self.__http = requests.Session()
            if self.using_proxy():
                self.__http.proxies = urllib.request.getproxies()
        elif self.request == 'requests-futures':
            self.__http = FuturesSession()
            if self.using_proxy():
                self.__http.proxies = urllib.request.getproxies()
        elif self.request == 'httplib2':
            self.__http = httplib2.Http()
        else:
            if self.scheme == 'http':
                self.__http = http_client.HTTPConnection(self.host, self.port)
            elif self.scheme == 'https':
                self.__http = http_client.HTTPSConnection(self.host, self.port)
                if self.using_proxy():
                    self.__http.set_tunnel(self.realhost, self.realport, self.proxy_headers) 
Example #3
Source File: apns.py    From zentral with Apache License 2.0 5 votes vote down vote up
def get_connection(self):
        self.conn = HTTP20Connection(self.APNs_PRODUCTION_SERVER,
                                     force_proto="h2",
                                     port=443, secure=True,
                                     ssl_context=self.get_ssl_context()) 
Example #4
Source File: connection.py    From alexa-voice-service-client with MIT License 5 votes vote down vote up
def create_connection(self, base_url=None):
        self.connection = HTTP20Connection(
            host=base_url or self.host, secure=True, force_proto='h2'
        ) 
Example #5
Source File: h2buster.py    From h2buster with GNU General Public License v3.0 5 votes vote down vote up
def h2_connect(s, ip, port, verify):
	if s == True:
		ctx = ssl.SSLContext()
		ctx.set_alpn_protocols(['h2'])
		if verify:
			ctx.verify_mode = ssl.CERT_REQUIRED
			ctx.load_default_certs()
		else: ctx.verify_mode = ssl.CERT_NONE
		conn = hyper.HTTP20Connection(ip, port=port, ssl_context=ctx)
	elif s == False:
		conn = hyper.HTTP20Connection(ip, port=port)
	conn.connect()
	return conn

# Function: main scan function. Starts up a number of processes which handle their own h2 connection and sends them entries to scan 
Example #6
Source File: alexa_communication.py    From python-alexa-voice-service with MIT License 5 votes vote down vote up
def init_connection(self):
        """ Opens and maintains the connection with AVS. This starts the thread that runs
            for the duration of the object's life. Sends required requests to initialize
            connection correctly. This should be called anytime the connection needs to be
            reestablished.

        """
        # Open connection
        self.connection = HTTP20Connection(self.url, port=443, secure=True, force_proto="h2", enable_push=True)

        # First start downstream
        self.start_downstream()

        # Send sync state message (required)
        header = {'namespace': "System", 'name': "SynchronizeState"}
        stream_id = self.send_event(header)
        # Manually handle this response for now
        data = self.get_response(stream_id)
        # Should be 204 response (no content)
        if data.status != 204:
            print("PUSH" + data.read())
            raise NameError("Bad status (%s)" % data.status)

        # Start ping thread
        ping_thread = threading.Thread(target=self.ping_thread)
        ping_thread.start() 
Example #7
Source File: check_ip.py    From XX-Net-mini with GNU General Public License v3.0 5 votes vote down vote up
def check_http2(self, ssl_sock, host):
        self.logger.debug("ip:%s use http/2", ssl_sock.ip_str)
        try:
            conn = hyper.HTTP20Connection(ssl_sock, host=host, ip=ssl_sock.ip_str, port=443)
            conn.request('GET', self.config.check_ip_path)
            response = conn.get_response()
            return response
        except Exception as e:
            self.logger.exception("http2 get response fail:%r", e)
            return False 
Example #8
Source File: client.py    From pushkin with MIT License 5 votes vote down vote up
def connect_to_apn_if_needed(self):
        if self.__connection is None:
            self.__connection = HTTP20Connection(self.server, self.port, ssl_context=self.ssl_context,
                                                 force_proto=self.proto or 'h2') 
Example #9
Source File: apns2.py    From django-db-mailer with GNU General Public License v2.0 4 votes vote down vote up
def send(token_hex, message, **kwargs):
    """
    Site: https://apple.com
    API: https://developer.apple.com
    Desc: iOS notifications

    Installation and usage:
    pip install hyper
    """

    priority = kwargs.pop('priority', 10)
    topic = kwargs.pop('topic', None)

    alert = {
        "title": kwargs.pop("event"),
        "body": message,
        "action": kwargs.pop(
            'apns_action', defaults.APNS_PROVIDER_DEFAULT_ACTION)
    }

    data = {
        "aps": {
            'alert': alert,
            'content-available': kwargs.pop('content_available', 0) and 1
        }
    }
    data['aps'].update(kwargs)
    payload = dumps(data, separators=(',', ':'))

    headers = {
        'apns-priority': priority
    }
    if topic is not None:
        headers['apns-topic'] = topic

    ssl_context = init_context()
    ssl_context.load_cert_chain(settings.APNS_CERT_FILE)
    connection = HTTP20Connection(
        settings.APNS_GW_HOST, settings.APNS_GW_PORT, ssl_context=ssl_context)

    stream_id = connection.request(
        'POST', '/3/device/{}'.format(token_hex), payload, headers)
    response = connection.get_response(stream_id)
    if response.status != 200:
        raise APNsError(response.read())
    return True