protected override async Task WriteResponse(MazeResponse response) { foreach (var package in _packages) { await response.Body.WriteAsync(package, 0, package.Length); } }
protected override async Task WriteResponse(MazeResponse response) { response.StatusCode = 303; var testResponse = Encoding.UTF8.GetBytes("Hello Universe!"); await response.Body.WriteAsync(testResponse, 0, testResponse.Length); }
public MazeRequestReceivedEventArgs(MazeRequest request, MazeResponse response, CancellationToken cancellationToken) { Request = request; Response = response; CancellationToken = cancellationToken; }
protected override async Task AssertReceivedResponse(MazeResponse response, HttpResponseMessage responseMessage) { var expected = Merge(_packages.Select(x => new ArraySegment <byte>(x)).ToList()); byte[] actual; if (responseMessage.Content.Headers.ContentEncoding.Contains("gzip")) { using (var result = new MemoryStream()) { using (var gzipStream = new GZipStream(await responseMessage.Content.ReadAsStreamAsync(), CompressionMode.Decompress)) { await gzipStream.CopyToAsync(result); } actual = result.ToArray(); } } else { using (var result = new MemoryStream()) { await responseMessage.Content.CopyToAsync(result); actual = result.ToArray(); } } Assert.Equal(expected.Length, actual.Length); Assert.Equal(expected, actual); }
private static void EncodeResponse(MazeResponse response, TextWriter textWriter) { textWriter.WriteLine(response.StatusCode); EncodeHeaders(response.Headers, textWriter); textWriter.WriteLine(); //finish }
public static int FormatResponse(MazeResponse mazeResponse, ArraySegment <byte> buffer) { var memoryStream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count, true); using (var streamWriter = new StreamWriter(memoryStream, Encoding, 8192, true)) EncodeResponse(mazeResponse, streamWriter); return((int)memoryStream.Position); }
private static long SetContentLength(MazeResponse response, RangeItemHeaderValue range) { var start = range.From.Value; var end = range.To.Value; var length = end - start + 1; response.ContentLength = length; return(length); }
protected override async Task AssertReceivedResponse(MazeResponse response, HttpResponseMessage responseMessage) { using (var memoryStream = new MemoryStream()) { await responseMessage.Content.CopyToAsync(memoryStream); var expected = Merge(_packages.Select(x => new ArraySegment <byte>(x)).ToList()); var actual = memoryStream.ToArray(); Assert.Equal(expected, actual); } }
public static HttpResponseMessage ToHttpResponseMessage(this MazeResponse response) { var message = new HttpResponseMessage((HttpStatusCode)response.StatusCode) { Content = new RawStreamContent(response.Body) }; response.Headers.CopyHeadersTo(message.Headers, message.Content.Headers); return(message); }
public DefaultMazeContext(MazeRequest request, MazeResponse response, IServiceProvider serviceProvider) { Request = request; Response = response; Request.Context = this; RequestServices = serviceProvider; _requestCancellationTokenSource = new CancellationTokenSource(); RequestAborted = _requestCancellationTokenSource.Token; }
private static void SetLastModifiedAndEtagHeaders(MazeResponse response, DateTimeOffset?lastModified, EntityTagHeaderValue etag) { var httpResponseHeaders = response.GetTypedHeaders(); if (lastModified.HasValue) { httpResponseHeaders.LastModified = lastModified; } if (etag != null) { httpResponseHeaders.ETag = etag; } }
protected override async Task AssertReceivedResponse(MazeResponse response, HttpResponseMessage responseMessage) { Assert.Contains(responseMessage.Content.Headers.ContentEncoding, s => s == "gzip"); using (var receiveStream = new MemoryStream()) { await responseMessage.Content.CopyToAsync(receiveStream); receiveStream.Position = 0; using (var result = new MemoryStream()) { using (var gzipStream = new GZipStream(receiveStream, CompressionMode.Decompress)) { await gzipStream.CopyToAsync(result); } var actual = result.ToArray(); Assert.Equal(_testData.Length, actual.Length); Assert.Equal(_testData, actual); } } }
public static ResponseHeaders GetTypedHeaders(this MazeResponse request) { return(new ResponseHeaders(request.Headers)); }
protected virtual Task AssertReceivedResponse(MazeResponse response, HttpResponseMessage responseMessage) { Assert.Equal(response.StatusCode, (int)responseMessage.StatusCode); return(Task.CompletedTask); }
private static void SetAcceptRangeHeader(MazeResponse response) { response.Headers[HeaderNames.AcceptRanges] = AcceptRangeHeaderValue; }
protected override Task WriteResponse(MazeResponse response) { response.StatusCode = StatusCodes.Status404NotFound; return(Task.CompletedTask); }
protected abstract Task WriteResponse(MazeResponse response);
protected override async Task AssertReceivedResponse(MazeResponse response, HttpResponseMessage responseMessage) { await base.AssertReceivedResponse(response, responseMessage); Assert.Equal("Hello Universe!", await responseMessage.Content.ReadAsStringAsync()); }
protected override Task WriteResponse(MazeResponse response) { return(response.Body.WriteAsync(_testData, 0, _testData.Length)); }
/// <summary> /// Registers an object for disposal by the host once the request has finished processing. /// </summary> /// <param name="response">The <see cref="MazeResponse" /></param> /// <param name="disposable">The object to be disposed.</param> public static void RegisterForDispose(this MazeResponse response, IDisposable disposable) { response.OnCompleted(DisposeDelegate, disposable); }
/// <summary> /// Adds a delegate to be invoked just before response headers will be sent to the client. /// </summary> /// <param name="response">The <see cref="MazeResponse" /></param> /// <param name="callback">The delegate to execute.</param> public static void OnStarting(this MazeResponse response, Func <Task> callback) { response.OnStarting(CallbackDelegate, callback); }