public void TestChunked() { ObjectPool<byte[]> pool = new ObjectPool<byte[]>(() => { return new byte[1024]; }); HttpChunkedServer server = new HttpChunkedServer(pool); try { server.Start(false); BlockingCollection<HttpResponse> responses = new BlockingCollection<HttpResponse>(); ClientSockNetChannel client = (ClientSockNetChannel)SockNetClient.Create(server.Endpoint, ClientSockNetChannel.DefaultNoDelay, ClientSockNetChannel.DefaultTtl, pool) .AddModule(new HttpSockNetChannelModule(HttpSockNetChannelModule.ParsingMode.Client)); client.Pipe.AddIncomingLast<HttpResponse>((ISockNetChannel channel, ref HttpResponse data) => { responses.Add(data); }); Assert.IsNotNull(client.Connect().WaitForValue(TimeSpan.FromSeconds(5))); HttpRequest request = new HttpRequest(client.BufferPool) { Action = "GET", Path = "/httpgallery/chunked/chunkedimage.aspx", Version = "HTTP/1.1" }; request.Header["Host"] = "www.httpwatch.com"; client.Send(request); HttpResponse response = null; responses.TryTake(out response, 10000); Assert.IsNotNull(response); Assert.IsNotNull(response.Version); Assert.IsNotNull(response.Code); Assert.IsNotNull(response.Reason); MemoryStream stream = new MemoryStream(); response.Write(stream, false); stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) { Console.WriteLine("Got response: " + reader.ReadToEnd()); } } finally { server.Stop(); } }
public void TestChunked() { ObjectPool <byte[]> pool = new ObjectPool <byte[]>(() => { return(new byte[1024]); }); HttpChunkedServer server = new HttpChunkedServer(pool); try { server.Start(false); BlockingCollection <HttpResponse> responses = new BlockingCollection <HttpResponse>(); ClientSockNetChannel client = (ClientSockNetChannel)SockNetClient.Create(server.Endpoint, ClientSockNetChannel.DefaultNoDelay, ClientSockNetChannel.DefaultTtl, pool) .AddModule(new HttpSockNetChannelModule(HttpSockNetChannelModule.ParsingMode.Client)); client.Pipe.AddIncomingLast <HttpResponse>((ISockNetChannel channel, ref HttpResponse data) => { responses.Add(data); }); Assert.IsNotNull(client.Connect().WaitForValue(TimeSpan.FromSeconds(5))); HttpRequest request = new HttpRequest(client.BufferPool) { Action = "GET", Path = "/httpgallery/chunked/chunkedimage.aspx", Version = "HTTP/1.1" }; request.Header["Host"] = "www.httpwatch.com"; client.Send(request); HttpResponse response = null; responses.TryTake(out response, 10000); Assert.IsNotNull(response); Assert.IsNotNull(response.Version); Assert.IsNotNull(response.Code); Assert.IsNotNull(response.Reason); MemoryStream stream = new MemoryStream(); response.Write(stream, false); stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) { Console.WriteLine("Got response: " + reader.ReadToEnd()); } } finally { server.Stop(); } }