internal static Handler GetBigChunkedHandler() { var chunks = new List <string> (); for (var i = 'A'; i < 'Z'; i++) { chunks.Add(new string (i, 1000)); } var content = new ChunkedContent(chunks); return(new PostHandler("Big Chunked", content, TransferMode.Chunked)); }
static IEnumerable <Handler> GetChunkedTests() { var chunks = new List <string> (); for (var i = 'A'; i < 'Z'; i++) { chunks.Add(new string (i, 1000)); } var content = new ChunkedContent(chunks); yield return(new PostHandler("Big Chunked", content, TransferMode.Chunked)); }
async Task<HttpResponse> HandlePostChunked ( TestContext ctx, HttpOperation operation, HttpConnection connection, HttpRequest request, RequestFlags effectiveFlags, CancellationToken cancellationToken) { var me = $"{ME}.{nameof (HandlePostChunked)}"; ctx.LogDebug (3, $"{me}: {connection.RemoteEndPoint}"); var firstChunk = await ChunkedContent.ReadChunk (ctx, request.Reader, cancellationToken).ConfigureAwait (false); ctx.LogDebug (3, $"{me} got first chunk: {firstChunk.Length}"); ctx.Assert (firstChunk, Is.EqualTo (ConnectionHandler.TheQuickBrownFoxBuffer), "first chunk"); readyTcs.TrySetResult (true); ctx.LogDebug (3, $"{me} reading remaining body"); await ChunkedContent.Read (ctx, request.Reader, cancellationToken).ConfigureAwait (false); return HttpResponse.CreateSuccess (ME); }
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); } }
protected internal override async Task <HttpResponse> HandleRequest( TestContext ctx, HttpOperation operation, HttpConnection connection, HttpRequest request, RequestFlags effectiveFlags, CancellationToken cancellationToken) { if (RemoteEndPoint == null) { RemoteEndPoint = connection.RemoteEndPoint; } await AbstractConnection.FinishedTask.ConfigureAwait(false); HttpContent content; switch (TestRunner.EffectiveType) { case HttpClientTestType.SimpleGZip: content = new GZipContent(ConnectionHandler.TheQuickBrownFoxBuffer); break; case HttpClientTestType.ReuseHandlerGZip: content = new GZipContent(ConnectionHandler.TheQuickBrownFoxBuffer); break; case HttpClientTestType.SequentialGZip: case HttpClientTestType.ParallelGZip: case HttpClientTestType.ParallelGZipNoClose: AssertNotReusingConnection(ctx, connection); content = new GZipContent(ConnectionHandler.TheQuickBrownFoxBuffer); break; case HttpClientTestType.SequentialRequests: AssertNotReusingConnection(ctx, connection); content = HttpContent.TheQuickBrownFox; break; case HttpClientTestType.ReuseHandler: case HttpClientTestType.ReuseHandlerNoClose: AssertReusingConnection(ctx, connection); content = HttpContent.TheQuickBrownFox; break; case HttpClientTestType.ReuseHandlerChunked: AssertReusingConnection(ctx, connection); content = new ChunkedContent(ConnectionHandler.TheQuickBrownFox); break; case HttpClientTestType.SequentialChunked: AssertNotReusingConnection(ctx, connection); content = new ChunkedContent(ConnectionHandler.TheQuickBrownFox); break; case HttpClientTestType.CancelPostWhileWriting: var currentRequest = (HttpClientRequest)operation.Request; await currentRequest.HandleCancelPost( ctx, connection, request, cancellationToken).ConfigureAwait(false); return(new HttpResponse(HttpStatusCode.OK, null)); default: throw ctx.AssertFail(TestRunner.EffectiveType); } return(new HttpResponse(HttpStatusCode.OK, content)); }
public override async Task WriteToAsync (TestContext ctx, Stream stream, CancellationToken cancellationToken) { ctx.LogDebug (4, $"{ME} WRITE BODY"); switch (TestRunner.EffectiveType) { case HttpRequestTestType.ReadTimeout: await stream.WriteAsync (ConnectionHandler.TheQuickBrownFoxBuffer, cancellationToken).ConfigureAwait (false); await stream.FlushAsync (cancellationToken); await Task.WhenAny (Request.WaitForCompletion (), Task.Delay (10000)); break; case HttpRequestTestType.PostChunked: await HandlePostChunked ().ConfigureAwait (false); break; case HttpRequestTestType.EntityTooBig: await ctx.AssertException<ProtocolViolationException> (() => stream.WriteAsync (ConnectionHandler.TheQuickBrownFoxBuffer, cancellationToken), "writing too many bytes").ConfigureAwait (false); break; case HttpRequestTestType.PostContentLength: await stream.WriteAsync (ConnectionHandler.TheQuickBrownFoxBuffer, cancellationToken).ConfigureAwait (false); await stream.FlushAsync (cancellationToken); break; case HttpRequestTestType.LargeChunkRead: await HandleLargeChunkRead ().ConfigureAwait (false); break; case HttpRequestTestType.GetNoLength: await stream.WriteAsync (ConnectionHandler.TheQuickBrownFoxBuffer, cancellationToken).ConfigureAwait (false); await stream.FlushAsync (cancellationToken); stream.Dispose (); break; default: throw ctx.AssertFail (TestRunner.EffectiveType); } async Task HandlePostChunked () { await stream.WriteAsync (ConnectionHandler.TheQuickBrownFoxBuffer, cancellationToken).ConfigureAwait (false); await stream.FlushAsync (cancellationToken); await AbstractConnection.WaitWithTimeout (ctx, 1500, Request.Handler.WaitUntilReady ()); await stream.WriteAsync (ConnectionHandler.GetLargeTextBuffer (50), cancellationToken); } async Task HandleLargeChunkRead () { await ChunkedContent.WriteChunkAsBlob ( stream, ConnectionHandler.TheQuickBrownFoxBuffer, cancellationToken).ConfigureAwait (false); await stream.FlushAsync (cancellationToken); await ChunkedContent.WriteChunkAsBlob ( stream, ConnectionHandler.GetLargeTextBuffer (50), cancellationToken); await ChunkedContent.WriteChunkTrailer (stream, cancellationToken); await stream.FlushAsync (cancellationToken); } }