public void Limiter_FileLength_Upgrade() { using (GetResetResponseLimiterSwindler()) { Test((builder) => { builder.UseResponseLimiter(10, 10); }, () => { ResponseLimiter.ModifyFileLengthLimit(20); var responses = new string[3]; for (int i = 0; i < 3; i++) { try { ResponseLimiter.AssertFileLength(i + 19); responses[i] = "Ok."; } catch (ApplicationException e) { responses[i] = e.Message; } } var actual = string.Join(" ", responses); Assert.AreEqual("Ok. Ok. File length limit exceeded.", actual); } ); } }
/// <summary> /// Processes the request. /// </summary> public async Task ProcessRequestCore() { if (!CheckPermissions()) { _context.Response.StatusCode = 404; return; } var httpHeaderTools = new HttpHeaderTools(_context); var endResponse = HandleResponseForClientCache(httpHeaderTools); if (endResponse) { return; } //TODO: CheckExecutableType feature is not ported yet from .net framework Services // It was designed to handle executable files like aspx or cshtml. // See the Repository.ExecutableExtensions property for the full list. //TODO: the ImgResizeApplication feature is not ported yet from .net framework Services await InitializeRequestedNodeAsync(); if (RequestedNode == null) { _context.Response.StatusCode = 404; return; } using (var binaryStream = GetConvertedStream(out var contentType, out var fileName)) { if (binaryStream == null) { return; } _context.Response.ContentType = contentType; _context.Response.Headers.Append(HeaderNames.ContentLength, binaryStream.Length.ToString()); httpHeaderTools.SetContentDispositionHeader(fileName); httpHeaderTools.SetCacheControlHeaders(lastModified: RequestedNode.ModificationDate, maxAge: MaxAge); _context.Response.StatusCode = 200; binaryStream.Position = 0; // Let ASP.NET handle sending bytes to the client. ResponseLimiter.AssertFileLength(binaryStream.Length); await binaryStream.CopyToAsync(_context.Response.Body); } // Let the client code log file downloads if (RequestedNode is File file) { File.Downloaded(file.Id); } }