Beispiel #1
0
        async Task <KFrameTrace> IFrameAsync(HttpRequest req, HttpResponse res, string remaining)
        {
            var trace = new KFrameTrace(KFrameTrace.TraceMethod.IFrame);

            res.Clear();
            var etag = req.Headers["If-None-Match"];

            if (!string.IsNullOrEmpty(etag) && etag == "\"iframe\"")
            {
                res.StatusCode = trace.StatusCode = (int)HttpStatusCode.NotModified;
                trace.FromETag = etag.ToString();
                return(trace);
            }
            var result = (List <object>)(await _repository.GetIFrameAsync(trace));

            trace.IFrames  = result.Select(x => (long)((dynamic)x).frame).ToArray();
            res.StatusCode = (int)HttpStatusCode.OK;
            res.Headers.Add("Access-Control-Allow-Origin", "*");
            res.ContentType = "application/json";
            var typedHeaders = res.GetTypedHeaders();

            typedHeaders.CacheControl = new CacheControlHeaderValue {
                Public = true, MaxAge = trace.MaxAge = KFrameTiming.IFrameCacheMaxAge()
            };
            typedHeaders.Expires = trace.Expires = KFrameTiming.IFrameCacheExpires();
            typedHeaders.ETag    = new EntityTagHeaderValue("\"iframe\"");
            trace.ETag           = "\"iframe\"";
            var json = JsonSerializer.Serialize(result);
            await res.WriteAsync(json);

            trace.ContentLength = res.ContentLength ?? json.Length;
            return(trace);
        }
Beispiel #2
0
        async Task IFrameAsync(HttpRequest req, HttpResponse res, string remaining)
        {
            res.Clear();
            var etag = req.Headers["If-None-Match"];

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

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

            typedHeaders.CacheControl = new CacheControlHeaderValue {
                Public = true, MaxAge = KFrameTiming.IFrameCacheMaxAge()
            };
            typedHeaders.Expires = KFrameTiming.IFrameCacheExpires();
            typedHeaders.ETag    = new EntityTagHeaderValue("\"iframe\"");
            var json = JsonConvert.SerializeObject((object)result);
            await res.WriteAsync(json);
        }