예제 #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 DnsEndPoint ("localhost", 5001));

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

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

                // Send a request (we're ignoring the response for now since it will be dumped to the console)
                await httpProtocol.SendAsync(new HttpRequestMessage(HttpMethod.Get, path));
            }
        }
예제 #2
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}");
            }
        }
예제 #4
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();
            }
        }
예제 #5
0
 public void Remove(HttpClientProtocol value)
 {
     m_list.Remove(value);
 }
예제 #6
0
 public void Add(HttpClientProtocol value)
 {
     // m_list.Add(value);
 }