Пример #1
0
        private static async Task HttpClient(IServiceProvider serviceProvider)
        {
            // TODO: Missing scenarios
            // - HTTP/2 needs to set the ALPN parameters (hard)
            // - Proxy support needs to know if the connection is secure

            // Build the client pipeline
            var client = new ClientBuilder(serviceProvider)
                         .UseSockets()
                         .UseDnsCaching(TimeSpan.FromHours(1))
                         .UseConnectionLogging()
                         .Build();

            await using var connection = await client.ConnectAsync(new IPEndPoint (IPAddress.Loopback, 5001));

            // Use the HTTP/1.1 protocol
            var httpProtocol = new HttpClientProtocol(connection);

            while (true)
            {
                Console.Write("http1.1> ");
                var path = Console.ReadLine();

                if (path == null)
                {
                    break;
                }

                if (path == string.Empty)
                {
                    path = "/";
                }

                var request = new HttpRequestMessage(HttpMethod.Get, path);
                request.Headers.Host = "localhost";

                var response = await httpProtocol.SendAsync(request);

                await response.Content.CopyToAsync(Console.OpenStandardOutput());

                Console.WriteLine();
            }
        }
        public override async Task OnConnectedAsync(ConnectionContext connection)
        {
            var httpConnection = new HttpClientProtocol(connection);

            int i = 1000;

            while (i-- > 0)
            {
                await Task.Delay(500);

                var response = await httpConnection.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/"), HttpCompletionOption.ResponseContentRead);

                if (!response.IsSuccessStatusCode)
                {
                    continue;
                }
                var content = await response.Content.ReadAsStringAsync();

                Console.WriteLine($"[{i}]: {content}");
            }
        }
Пример #3
0
        private static async Task DockerDaemon(IServiceProvider serviceProvider)
        {
            var client = new ClientBuilder(serviceProvider)
                         .UseConnectionFactory(new NamedPipeConnectionFactory())
                         .UseConnectionLogging()
                         .Build();

            await using var connection = await client.ConnectAsync(new NamedPipeEndPoint ("docker_engine"));

            // Use the HTTP/1.1 protocol
            var httpProtocol = new HttpClientProtocol(connection);

            while (true)
            {
                // Console.Write("http1.1> ");
                var path = Console.ReadLine();

                if (path == null)
                {
                    break;
                }

                // Console.WriteLine();

                if (path == string.Empty)
                {
                    path = "/";
                }

                var request = new HttpRequestMessage(HttpMethod.Get, path);
                request.Headers.Host = "localhost";

                var response = await httpProtocol.SendAsync(request);

                await response.Content.CopyToAsync(Console.OpenStandardOutput());

                Console.WriteLine();
            }
        }