public async void Settings_Disable_Push_Promise () { var url = new Uri ("http://localhost:8999/index.html"); var settings = new Http2ConnectionSettings (url) { DisablePushPromise = true }; var http = new Http2Client (settings); await http.Connect (); var didAck = false; var semaphoreSettings = new SemaphoreSlim (0); var cancelTokenSource = new CancellationTokenSource (); var connectionStream = await http.StreamManager.Get (0); connectionStream.OnFrameReceived += (frame) => { // Watch for an ack'd settings frame after we sent the frame with no push promise if (frame.Type == FrameType.Settings) { if ((frame as SettingsFrame).Ack) { didAck = true; semaphoreSettings.Release (); } } }; cancelTokenSource.CancelAfter (TimeSpan.FromSeconds (2)); await semaphoreSettings.WaitAsync (cancelTokenSource.Token); Assert.IsTrue (didAck); }
public async void Settings_Disable_Push_Promise() { var url = new Uri("http://localhost:8999/index.html"); var settings = new Http2ConnectionSettings(url) { DisablePushPromise = true }; var http = new Http2Client(settings); await http.Connect(); var didAck = false; var semaphoreSettings = new SemaphoreSlim(0); var cancelTokenSource = new CancellationTokenSource(); var connectionStream = await http.StreamManager.Get(0); connectionStream.OnFrameReceived += (frame) => { // Watch for an ack'd settings frame after we sent the frame with no push promise if (frame.Type == FrameType.Settings) { if ((frame as SettingsFrame).Ack) { didAck = true; semaphoreSettings.Release(); } } }; cancelTokenSource.CancelAfter(TimeSpan.FromSeconds(2)); await semaphoreSettings.WaitAsync(cancelTokenSource.Token); Assert.IsTrue(didAck); }
public async void GoAway() { var uri = new Uri("http://localhost:8999/index.html"); var http = new Http2Client(uri); await http.Connect(); var cancelTokenSource = new CancellationTokenSource(); cancelTokenSource.CancelAfter(TimeSpan.FromSeconds(2)); var sentGoAway = await http.Disconnect(); Assert.IsTrue(sentGoAway); }
public async void Ping() { var uri = new Uri("http://localhost:8999/index.html"); var http = new Http2Client(uri); var data = System.Text.Encoding.ASCII.GetBytes("PINGPONG"); var cancelTokenSource = new CancellationTokenSource(); cancelTokenSource.CancelAfter(TimeSpan.FromSeconds(2)); var pong = await http.Ping(data, cancelTokenSource.Token); Assert.IsTrue(pong); }
public void TestMethod1Async() { string url = "https://cdn-dl.fotoable.com/conf/test-now/testnowConfig.json"; //string url = "https://static.zhihu.com/heifetz/main.raven.887de2ac64cec5fbc8e2.js"; var uri = new Uri(url); // Create a Http2Client var http2 = new Http2Client(uri); var headers = new NameValueCollection(); byte[] data = null; var response = http2.Send(uri, HttpMethod.Get, headers, data).GetAwaiter().GetResult(); Assert.IsTrue(response.Status == System.Net.HttpStatusCode.OK); }
static async Task sendHttp2() { // Uri to request var uri = new Uri("https://localhost:8443/"); // Create a Http2Client var http2 = new Http2Client(uri); // Specify any custom headers var headers = new NameValueCollection(); headers.Add("some-header", "value"); // For some requests you may have a request body byte[] data = null; http2.Connect(); //var response = await http2.Send(uri, HttpMethod.Get, headers, data); }
public async void Get_Send_Headers_With_Continuation() { var uri = new Uri("http://localhost:8999/index.html"); var http = new Http2Client(uri); // Generate some gibberish custom headers var headers = new NameValueCollection(); for (int i = 0; i < 1000; i++) { headers.Add("custom-" + i, "HEADER-VALUE-" + i); } var response = await http.Send(uri, HttpMethod.Get, headers, new byte[0]); var data = System.Text.Encoding.ASCII.GetString(response.Body); Assert.IsNotNullOrEmpty(data); Assert.IsTrue(data.Contains("Hello World")); }
static void WebHostTest() { WebHost webHost = new WebHost(port: 8088); webHost.Start(); ConsoleHelper.WriteLine("WebHost http2.0 已启动"); var url = "http://127.0.0.1:8088"; ConsoleHelper.WriteLine($"请在浏览器中输入URL:{url}"); Http2Client http2Client1 = new Http2Client(new Uri(url)); var result1 = http2Client1.Get().GetAwaiter().GetResult(); var result11 = http2Client1.Get().GetAwaiter().GetResult(); Http2Client http2Client2 = new Http2Client(new Uri(url)); var result2 = http2Client2.Post("name=yswenli").GetAwaiter().GetResult(); }
public TResponse BlockingUnaryCall <TRequest, TResponse>(Method <TRequest, TResponse> method, string host, CallOptions options, TRequest request) where TResponse : class { Http2Client client = channel.client; byte[] serialized = method.RequestMarshaller.Serializer(request); NameValueCollection header = new NameValueCollection(); header.Add(Constants.ContentTypeKey, Constants.ContentTypeVal); header.Add(Constants.UserAgentKey, Constants.UserAgentVal); var response = client.Post(new Uri(channel.Host, method.ServiceName), header, serialized); if (response.Status != HttpStatusCode.OK) { return(null); } return(method.ResponseMarshaller.Deserializer(response.Body)); }
public async void GoAway () { var uri = new Uri ("http://localhost:8999/index.html"); var http = new Http2Client (uri); await http.Connect (); var cancelTokenSource = new CancellationTokenSource (); cancelTokenSource.CancelAfter (TimeSpan.FromSeconds (2)); var sentGoAway = await http.Disconnect (); Assert.IsTrue (sentGoAway); }
public async void Ping () { var uri = new Uri ("http://localhost:8999/index.html"); var http = new Http2Client (uri); var data = System.Text.Encoding.ASCII.GetBytes ("PINGPONG"); var cancelTokenSource = new CancellationTokenSource (); cancelTokenSource.CancelAfter (TimeSpan.FromSeconds (2)); var pong = await http.Ping (data, cancelTokenSource.Token); Assert.IsTrue (pong); }
public async void Get_Send_Headers_With_Continuation () { var uri = new Uri ("http://localhost:8999/index.html"); var http = new Http2Client (uri); // Generate some gibberish custom headers var headers = new NameValueCollection (); for (int i = 0; i < 1000; i++) headers.Add ("custom-" + i, "HEADER-VALUE-" + i); var response = await http.Send (uri, HttpMethod.Get, headers, new byte[0]); var data = System.Text.Encoding.ASCII.GetString (response.Body); Assert.IsNotNullOrEmpty (data); Assert.IsTrue (data.Contains ("Hello World")); }