public async Task should_consume_stream_at_the_server_side() { const int totalLength = 1000 * 1024 * 1024; var stream = new FixedLengthStream(totalLength); StreamContent streamContent = CreateStreamContent( stream, "application/octet-stream", "executable.txt"); HttpRequestMessage request = CreateRequest(streamContent); Stopwatch watch = Stopwatch.StartNew(); HttpResponseMessage response = await Client.SendAsync( request, HttpCompletionOption.ResponseHeadersRead); watch.Stop(); output.WriteLine($"Elapsed: {watch.Elapsed}."); output.WriteLine($"Position: {stream.Position}."); Assert.Equal(HttpStatusCode.OK, response.StatusCode); string content = await response.Content.ReadAsStringAsync(); var json = JsonConvert.DeserializeAnonymousType( content, new { ConsumedLength = default(long) }); Assert.Equal(stream.Length, json.ConsumedLength); }
static StreamContent CreateStreamContent( FixedLengthStream countedStream, string contentType, string fileName) { #region Please implement the method to create the stream content /* * You should create a streaming content and set the content type as well as * fileName in the correspond content releated headers. */ throw new NotImplementedException(); #endregion }
public async Task should_check_header_quickly_at_the_server_side() { const int totalLength = 1000 * 1024 * 1024; var stream = new FixedLengthStream(totalLength); StreamContent streamContent = CreateStreamContent( stream, "application/octet-stream", "executable.exe"); HttpRequestMessage request = CreateRequest(streamContent); Stopwatch watch = Stopwatch.StartNew(); HttpResponseMessage response = await Client.SendAsync( request, HttpCompletionOption.ResponseHeadersRead); watch.Stop(); output.WriteLine($"Elapsed: {watch.Elapsed}."); output.WriteLine($"Position: {stream.Position}."); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); }
static StreamContent CreateStreamContent( FixedLengthStream countedStream, string contentType, string fileName) { #region Please implement the method to create the stream content /* * You should create a streaming content and set the content type as well as * fileName in the correspond content releated headers. */ var content = new StreamContent(countedStream); content.Headers.ContentType = new MediaTypeHeaderValue(contentType); content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; return(content); #endregion }
static StreamContent CreateStreamContent( FixedLengthStream countedStream, string contentType, string fileName) {