How to use the awscrt.http.HttpClientConnection.new function in awscrt

To help you get started, we’ve selected a few awscrt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github awslabs / aws-crt-python / test / test_http_client.py View on Github external
def _new_client_connection(self, secure, proxy_options=None):
        if secure:
            tls_ctx_opt = TlsContextOptions()
            tls_ctx_opt.override_default_trust_store_from_path(None, 'test/resources/unittests.crt')
            tls_ctx = ClientTlsContext(tls_ctx_opt)
            tls_conn_opt = tls_ctx.new_connection_options()
            tls_conn_opt.set_server_name(self.hostname)
        else:
            tls_conn_opt = None

        event_loop_group = EventLoopGroup()
        host_resolver = DefaultHostResolver(event_loop_group)
        bootstrap = ClientBootstrap(event_loop_group, host_resolver)
        connection_future = HttpClientConnection.new(host_name=self.hostname,
                                                     port=self.port,
                                                     bootstrap=bootstrap,
                                                     tls_connection_options=tls_conn_opt,
                                                     proxy_options=proxy_options)
        return connection_future.result(self.timeout)
github awslabs / aws-crt-python / elasticurl.py View on Github external
data_stream = None

if args.data:
    data_bytes = args.data.encode(encoding='utf-8')
    data_len = len(data_bytes)
    data_stream = BytesIO(data_bytes)
elif args.data_file:
    data_len = os.stat(args.data_file).st_size
    data_stream = open(args.data_file, 'rb')


socket_options = io.SocketOptions()
socket_options.connect_timeout_ms = args.connect_timeout

hostname = url.hostname
connect_future = http.HttpClientConnection.new(
    host_name=hostname,
    port=port,
    socket_options=socket_options,
    tls_connection_options=tls_connection_options,
    bootstrap=client_bootstrap)

connection = connect_future.result(10)
connection.shutdown_future.add_done_callback(on_connection_shutdown)

request = http.HttpRequest(args.method, body_stream=data_stream)

if args.get:
    request.method = "GET"

if args.post:
    request.method = "POST"
github aws / aws-iot-device-sdk-python-v2 / awsiot / greengrass_discovery.py View on Github external
request = HttpRequest(
                    method='GET',
                    path='/greengrass/discover/thing/{}'.format(thing_name),
                    headers=headers)

                http_stream = connection.request(
                    request=request,
                    on_body=on_incoming_body)
               
                http_stream.activate()
                http_stream.completion_future.add_done_callback(on_request_complete)

            except Exception as e:
                discovery['future'].set_exception(e)

        connect_future = HttpClientConnection.new(
            host_name=self._gg_server_name,
            port=self.port,
            socket_options=self._socket_options,
            tls_connection_options = self._tls_connection_options,
            bootstrap = self._bootstrap)

        connect_future.add_done_callback(on_connection_completed)

        return discovery['future']