Beispiel #1
0
        async Task PFrameAsync(HttpRequest req, HttpResponse res, string remaining)
        {
            res.Clear();
            if (string.IsNullOrEmpty(remaining) || remaining[0] != '/')
            {
                res.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }
            if (!long.TryParse(remaining.Substring(1), out var iframe))
            {
                res.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }
            var etag = req.Headers["If-None-Match"];

            if (!string.IsNullOrEmpty(etag) && _repository.HasPFrame(etag))
            {
                res.StatusCode = (int)HttpStatusCode.NotModified;
                return;
            }
            var result = await _repository.GetPFrameAsync(iframe);

            res.StatusCode  = (int)HttpStatusCode.OK;
            res.ContentType = "application/json";
            res.Headers.Add("Access-Control-Allow-Origin", "*");
            var typedHeaders = res.GetTypedHeaders();

            typedHeaders.CacheControl = new CacheControlHeaderValue {
                NoCache = true
            };
            //typedHeaders.Expires = DateTime.Today.ToUniversalTime().AddDays(1);
            typedHeaders.ETag = new EntityTagHeaderValue(result.ETag);
            var json = JsonConvert.SerializeObject(result.Result);
            await res.WriteAsync(json);
        }