private void AddHeaders(HttpResponse httpResponse, RendertronOptions options, bool isPrerendered)
 {
     if (options.AddVeryUserAgentHeader)
     {
         httpResponse.Headers.Append(HeaderNames.Vary, "User-Agent");
     }
     if (options.AddPrerenderedHeader)
     {
         httpResponse.Headers["Prerendered"] = new string[] { isPrerendered ? "1" : "0" };
     }
 }
 private void AddHttpCacheHeaders(HttpResponse httpResponse, RendertronOptions options)
 {
     if (options.HttpCacheMaxAge > TimeSpan.Zero)
     {
         httpResponse.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
         {
             Public = true,
             MaxAge = options.HttpCacheMaxAge
         };
     }
 }
Esempio n. 3
0
 private void AddHttpCacheHeaders(HttpResponse httpResponse, RendertronOptions options)
 {
     if (options.HttpCacheMaxAge > TimeSpan.Zero)
     {
         httpResponse.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
         {
             Public = true,
             MaxAge = options.HttpCacheMaxAge
         };
         httpResponse.Headers[HeaderNames.Vary] = new string[] { "Accept-Encoding" };
     }
 }
Esempio n. 4
0
        private async Task InvokeRender(HttpContext context, RendertronOptions options)
        {
            var cancellationToken = context.RequestAborted;

            var response = await _rendertronClient
                           .RenderAsync(context.Request.GetDisplayUrl(), cancellationToken)
                           .ConfigureAwait(false);

            AddHttpCacheHeaders(context.Response, options);
            context.Response.StatusCode = (int)response.StatusCode;
            await context.Response.WriteAsync(response.Result, cancellationToken);
        }
        private bool IsNeedRender(HttpContext context, RendertronOptions options)
        {
            var userAgent = context.Request.Headers["User-agent"].ToString().ToLowerInvariant();
            var path      = context.Request.Path.Value;

            if (options.ExtensionBlacklist.Any(ext => path.EndsWith("." + ext)))
            {
                return(false);
            }

            if (options.PathPrefixBlacklist.Any(prefix => path.StartsWith(prefix)))
            {
                return(false);
            }

            return(options.UserAgents.Any(x => userAgent.Contains(x.ToLowerInvariant())));
        }
Esempio n. 6
0
        private bool IsNeedRender(HttpContext context, RendertronOptions options)
        {
            var userAgent = context.Request.Headers["User-agent"].ToString().ToLowerInvariant();

            return(options.UserAgents.Any(x => userAgent.Contains(x.ToLowerInvariant())));
        }