Esempio n. 1
0
			protected override Task WriteBody (TestContext ctx, CancellationToken cancellationToken)
			{
				switch (TestRunner.EffectiveType) {
				case HttpRequestTestType.PutChunked:
				case HttpRequestTestType.PutChunkDontCloseRequest:
					return PutChunked ();

				case HttpRequestTestType.EntityTooBig:
					return EntityTooBig ();

				case HttpRequestTestType.PostContentLength:
					return PostContentLength ();

				case HttpRequestTestType.ClientAbortsPost:
					return ClientAbortsPost ();

				default:
					return base.WriteBody (ctx, cancellationToken);
				}

				async Task EntityTooBig ()
				{
					var stream = await RequestExt.GetRequestStreamAsync ().ConfigureAwait (false);
					await Content.WriteToAsync (ctx, stream, cancellationToken).ConfigureAwait (false);
					// This throws on .NET
					try { stream.Dispose (); } catch { }
				}

				async Task PostContentLength ()
				{
					using (var stream = await RequestExt.GetRequestStreamAsync ().ConfigureAwait (false)) {
						await AbstractConnection.WaitWithTimeout (ctx, 1500, Handler.WaitUntilReady ());
						await Content.WriteToAsync (ctx, stream, cancellationToken);
						stream.Flush ();
					}
				}

				async Task PutChunked ()
				{
					var stream = await RequestExt.GetRequestStreamAsync ().ConfigureAwait (false);
					try {
						await Content.WriteToAsync (ctx, stream, cancellationToken).ConfigureAwait (false);
						await stream.FlushAsync ();
					} finally {
						if (TestRunner.EffectiveType == HttpRequestTestType.PutChunked)
							stream.Dispose ();
					}
				}

				async Task ClientAbortsPost ()
				{
					var stream = await RequestExt.GetRequestStreamAsync ().ConfigureAwait (false);
					try {
						stream.Dispose ();
					} catch (Exception ex) {
						ctx.LogDebug (4, $"{ME} GOT EX: {ex.Message}");
					}
				}
			}
Esempio n. 2
0
			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);
				}
			}