示例#1
0
        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);
        }
示例#2
0
        public async Task InvokeAsync(HttpContext context)
        {
            if (!context.Request.Query.TryGetValue("id", out var id))
            {
                context.Response.StatusCode = 404;
                await context.Response.WriteAsync("Missing required parameter: id");

                return;
            }

            var result = await _storage.TryGetDetailByIdAsync(id);

            if (!result.Succeed || result.Value == null)
            {
                context.Response.StatusCode = 404;
                return;
            }

            context.Response.StatusCode  = 200;
            context.Response.ContentType = "application/json";
            await context.Response.WriteAsync(JsonSerializer.Serialize(new RequestRecordDetailPayload(result.Value)));
        }
示例#3
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);
        }