public async Task InvokeAsync(HttpContext context) { var result = await _storage.TryGetDetailByIdAsync(context.Request.Query["id"]); var resultBody = await _storage.TryGetResponseBodyByIdAsync(context.Request.Query["id"]); var entry = result.Value; if (!result.Succeed || !resultBody.Succeed || entry == null) { context.Response.StatusCode = 404; return; } var contentType = (entry.ResponseHeaders != null) ? entry.ResponseHeaders.TryGetValue("Content-Type", out var headers) ? headers.FirstOrDefault() : "application/octet-stream" : "application/octet-stream"; context.Response.ContentType = "application/octet-stream"; context.Response.StatusCode = 200; var contentDisposition = new ContentDispositionHeaderValue("attachment"); contentDisposition.SetHttpFileName(entry.Id + FileNameHelper.GetExtension(entry.Path, contentType)); context.Response.GetTypedHeaders().ContentDisposition = contentDisposition; await context.Response.Body.WriteAsync(resultBody.Value ?? Array.Empty <byte>(), 0, resultBody.Value?.Length ?? 0); }
public async Task InvokeAsync(HttpContext context) { var result = await _storage.TryGetDetailByIdAsync(context.Request.Query["id"]); var resultBody = await _storage.TryGetRequestBodyByIdAsync(context.Request.Query["id"]); if (!result.Succeed || !resultBody.Succeed) { context.Response.StatusCode = 404; return; } var entry = result.Value; var contentType = entry.RequestHeaders["Content-Type"].FirstOrDefault(); context.Response.ContentType = "application/octet-stream"; context.Response.StatusCode = 200; var contentDisposition = new ContentDispositionHeaderValue("attachment"); contentDisposition.SetHttpFileName(entry.Id + FileNameHelper.GetExtension(entry.Path, contentType)); context.Response.GetTypedHeaders().ContentDisposition = contentDisposition; await context.Response.Body.WriteAsync(resultBody.Value, 0, resultBody.Value.Length); }