/// <summary>Echoes all request data back into the response</summary> static async void EchoHandler(IStream stream) { try { // Consume headers var headers = await stream.ReadHeadersAsync(); // Send response headers var responseHeaders = new HeaderField[] { new HeaderField { Name = ":status", Value = "200" }, new HeaderField { Name = "nextone", Value = "i am a header value" }, }; await stream.WriteHeadersAsync(responseHeaders, false); // Write request payload back into response await stream.CopyToAsync(stream); // Write end of stream await stream.WriteAsync(new ArraySegment <byte>(emptyBody), true); } catch (Exception e) { Console.WriteLine("Error during handling request: {0}", e.Message); stream.Cancel(); } }
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return(stream.CopyToAsync(destination, bufferSize, cancellationToken)); }