Beispiel #1
0
        public async Task InvokeAsync(
            HttpContext context,
            IAssetStorage assetStore)
        {
            Guid id = Guid.Parse((string)context.GetRouteValue("id"));

            Asset asset = await assetStore.GetAssetAsync(id);

            using (Stream assetStream = await assetStore.DownloadAsync(id))
            {
                context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
                {
                    Public = true, MaxAge = TimeSpan.FromDays(30)
                };
                context.Response.GetTypedHeaders().ETag = new EntityTagHeaderValue($"\"{asset.Hash}\"");
                context.Response.ContentType   = asset.MimeType;
                context.Response.ContentLength = assetStream.Length;

                await assetStream.CopyToAsync(context.Response.Body);
            }
        }