public async Task <IActionResult> Execute(string id, HttpContext httpContext)
        {
            if (!_PublishingId.Validate(id))
            {
                return(new BadRequestResult());
            }

            var e = await _SafeReader.Execute(id);

            if (e == null)
            {
                return(new NotFoundResult());
            }

            var r = new BinaryContentResponse
            {
                LastModified          = e.Release,
                PublishingId          = e.PublishingId,
                ContentTypeName       = e.ContentTypeName,
                Content               = e.Content,
                SignedContentTypeName = e.SignedContentTypeName,
                SignedContent         = e.SignedContent
            };

            return(new OkObjectResult(r));
        }
        public async Task Execute(HttpContext httpContext, string id)
        {
            if (httpContext.Request.Headers.TryGetValue("if-none-match", out var etagValue))
            {
                httpContext.Response.ContentLength = 0;
                httpContext.Response.StatusCode    = 400; //TODO!
            }

            var parsed = _PublishingId.ParseUri(id);

            if (typeof(T) != typeof(ManifestEntity) && !_PublishingId.Validate(id))
            {
                httpContext.Response.StatusCode    = 400;
                httpContext.Response.ContentLength = 0;
            }

            var content = await _SafeReader.Execute(parsed);

            if (content == null)
            {
                //TODO tell CDN to ignore hunting?
                httpContext.Response.StatusCode    = 404;
                httpContext.Response.ContentLength = 0;
                return;
            }

            if (etagValue == content.PublishingId)
            {
                httpContext.Response.StatusCode    = 304;
                httpContext.Response.ContentLength = 0;
                return;
            }

            var accepts = httpContext.Request.Headers["accept"].ToHashSet();

            var signedResponse = content.SignedContentTypeName != null && accepts.Contains(content.SignedContentTypeName);

            if (!signedResponse && !accepts.Contains(content.ContentTypeName))
            {
                httpContext.Response.StatusCode    = 406;
                httpContext.Response.ContentLength = 0;
                return;
            }

            httpContext.Response.Headers.Add("etag", content.PublishingId);
            httpContext.Response.Headers.Add("last-modified", content.Release.ToUniversalTime().ToString("r"));
            httpContext.Response.Headers.Add("content-type", signedResponse ? content.SignedContentTypeName : content.ContentTypeName);
            httpContext.Response.Headers.Add("x-vws-signed", signedResponse.ToString());

            httpContext.Response.StatusCode    = 200;
            httpContext.Response.ContentLength = (signedResponse ? content.SignedContent : content.Content).Length;
            await httpContext.Response.Body.WriteAsync(signedResponse?content.SignedContent : content.Content);
        }
예제 #3
0
 public IEnumerable <T> Execute <T>(string collectionName, IMongoQuery mongoQuery)
 {
     return(_reader.Execute <T>(collectionName, mongoQuery));
 }
예제 #4
0
 public Task <IEnumerable <T> > ExecuteAsync <T>(string collectionName, IMongoQuery mongoQuery)
 {
     return(Task.Run(() => { return _reader.Execute <T>(collectionName, mongoQuery); }));
 }