Beispiel #1
0
        private static async Task Echo(SecurePipelineConnection pipeline)
        {
            try
            {
                while (true)
                {
                    var result = await pipeline.Input.ReadAsync();

                    var request = result.Buffer;

                    if (request.IsEmpty && result.IsCompleted)
                    {
                        pipeline.Input.Advance(request.End);
                        return;
                    }
                    var response = pipeline.Output.Alloc();
                    response.Write(Encoding.UTF8.GetBytes("HTTP/1.1 200 OK"));
                    response.Write(Encoding.UTF8.GetBytes("\r\nContent-Length: 13"));
                    response.Write(Encoding.UTF8.GetBytes("\r\nContent-Type: text/plain"));
                    response.Write(Encoding.UTF8.GetBytes("\r\nConnection: close"));
                    response.Write(Encoding.UTF8.GetBytes("\n\r\n"));
                    response.Write(Encoding.UTF8.GetBytes("Hello, World!"));
                    await response.FlushAsync();

                    pipeline.Input.Advance(request.End);
                    pipeline.Output.Complete();
                }
            }
            finally
            {
            }
        }
Beispiel #2
0
        private async Task Echo(SecurePipelineConnection pipeline)
        {
            try
            {
                while (true)
                {
                    var result = await pipeline.Input.ReadAsync();

                    var request = result.Buffer;

                    if (request.IsEmpty && result.IsCompleted)
                    {
                        pipeline.Input.Advance(request.End);
                        break;
                    }
                    int len      = request.Length;
                    var response = pipeline.Output.Alloc();
                    var sb       = new StringBuilder();
                    sb.AppendLine("HTTP/1.1 200 OK");
                    sb.AppendLine("Content-Length: 13");
                    sb.Append("Content-Type: text/plain");
                    sb.Append("\r\n\r\n");
                    sb.Append("Hello, World!");
                    response.Write(Encoding.UTF8.GetBytes(sb.ToString()));
                    await response.FlushAsync();

                    pipeline.Input.Advance(request.End);
                    return;
                }
                pipeline.Input.Complete();
                pipeline.Output.Complete();
            }
            catch (Exception ex)
            {
                pipeline.Input.Complete(ex);
                pipeline.Output.Complete(ex);
            }
        }
Beispiel #3
0
 public TlsAdaptedConnection(SecurePipelineConnection connection)
 {
     _connection = connection;
     _stream     = _connection.GetStream();
 }