Пример #1
0
 public ClientHandler(Session session, Socket clientSocket)
 {
     _session = session;
     _socket  = clientSocket;
     _stream  = new ManualBufferedStream(new ConnectionStream(_connection), _session.BufferAllocator);
     _reader  = new HttpStreamReader(_stream);
 }
Пример #2
0
        public override async Task Initialize(TestContext ctx, HttpOperation operation, CancellationToken cancellationToken)
        {
            remoteEndPoint = (IPEndPoint)Socket.RemoteEndPoint;
            ctx.LogDebug(5, $"{ME} INITIALIZE: {ListenSocket?.LocalEndPoint} {remoteEndPoint} {operation?.ME}");
            if (operation != null)
            {
                networkStream = operation.CreateNetworkStream(ctx, Socket, true);
            }
            if (networkStream == null)
            {
                networkStream = new NetworkStream(Socket, true);
            }

            if (Server.SslStreamProvider != null)
            {
                sslStream = await CreateSslStream(ctx, networkStream, cancellationToken).ConfigureAwait(false);

                Stream = sslStream;
            }
            else
            {
                Stream = networkStream;
            }

            reader = new HttpStreamReader(Stream);
            ctx.LogDebug(5, $"{ME} INITIALIZE DONE: {ListenSocket?.LocalEndPoint} {remoteEndPoint}");
        }
Пример #3
0
        public void TestMethod1()
        {
            var mem = new MemoryStream(
                Encoding.UTF8.GetBytes("4\r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"));

            var reader = new HttpStreamReader(mem);
            var body   = reader.ReadChunckedBodyAsync().Result;

            Assert.AreEqual("Wikipedia in\r\n\r\nchunks.", Encoding.UTF8.GetString(body));
        }
Пример #4
0
        public void TestMethod2()
        {
            var mem = File.ReadAllText(@".\Data\chunked.txt", Encoding.UTF8);

            var reader = new HttpStreamReader(new MemoryStream(Encoding.UTF8.GetBytes(mem)));
            var body   = Encoding.UTF8.GetString(reader.ReadChunckedBodyAsync().Result);

            var expected = File.ReadAllText(@".\Data\processed.txt", Encoding.UTF8);

            Assert.AreEqual(expected, body);
        }
Пример #5
0
 protected override void Close()
 {
     if (reader != null)
     {
         reader.Dispose();
         reader = null;
     }
     if (writer != null)
     {
         writer.Dispose();
         writer.Dispose();
     }
     if (sslStream != null)
     {
         sslStream.Dispose();
         sslStream = null;
     }
     if (networkStream != null)
     {
         try {
             networkStream.Dispose();
         } catch {
             ;
         } finally {
             networkStream = null;
         }
     }
     if (Stream != null)
     {
         try {
             Stream.Dispose();
         } catch {
             ;
         } finally {
             Stream = null;
         }
     }
     if (Socket != null)
     {
         try {
             Socket.Shutdown(SocketShutdown.Both);
         } catch {
             ;
         } finally {
             Socket.Close();
             Socket.Dispose();
             Socket = null;
         }
     }
 }
Пример #6
0
        public override async Task Initialize(TestContext ctx, CancellationToken cancellationToken)
        {
            networkStream = new NetworkStream(Socket, true);

            if (Server.SslStreamProvider != null)
            {
                sslStream = await CreateSslStream(ctx, networkStream, cancellationToken).ConfigureAwait(false);

                Stream = sslStream;
            }
            else
            {
                Stream = networkStream;
            }

            reader           = new HttpStreamReader(Stream);
            writer           = new StreamWriter(Stream);
            writer.AutoFlush = true;
        }
Пример #7
0
 async Task <HttpContent> ReadBody(HttpMessage message, CancellationToken cancellationToken)
 {
     TestContext.LogDebug(5, "READ BODY: {0}", message);
     using (var reader = new HttpStreamReader(Context.Request.InputStream)) {
         cancellationToken.ThrowIfCancellationRequested();
         if (message.ContentType != null && message.ContentType.Equals("application/octet-stream"))
         {
             return(await BinaryContent.Read(reader, message.ContentLength.Value, cancellationToken));
         }
         if (message.ContentLength != null)
         {
             return(await StringContent.Read(reader, message.ContentLength.Value, cancellationToken));
         }
         if (message.TransferEncoding != null)
         {
             if (!message.TransferEncoding.Equals("chunked"))
             {
                 throw new InvalidOperationException();
             }
             return(await ChunkedContent.ReadNonChunked(reader, cancellationToken));
         }
         return(null);
     }
 }