Ejemplo n.º 1
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements
        ///     the <see cref="T:System.Web.IHttpHandler"></see> interface.
        /// </summary>
        /// <param name="context">
        /// An <see cref="T:System.Web.HttpContext"></see> object that provides references
        ///     to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.
        /// </param>
        public void ProcessRequest(HttpContext context)
        {
            if (!Security.IsAuthorizedTo(Rights.ViewPublicPosts))
            {
                context.Response.StatusCode = 401;
                return;
            }

            var title  = RetrieveTitle(context);
            var format = RetrieveFormat(context);
            var list   = GenerateItemList(context);

            list = CleanList(list);

            if (string.IsNullOrEmpty(context.Request.QueryString["post"]))
            {
                // Shorten the list to the number of posts stated in the settings, except for the comment feed.
                var max = Math.Min(BlogSettings.Instance.PostsPerFeed, list.Count);
                list = list.FindAll(item => item.IsVisible);

                list = list.GetRange(0, max);
            }

            SetHeaderInformation(context, list, format);

            if (BlogSettings.Instance.EnableHttpCompression)
            {
                CompressionModule.CompressResponse(context);
            }

            var generator = new SyndicationGenerator(BlogSettings.Instance, Category.Categories);

            generator.WriteFeed(format, context.Response.OutputStream, list, title);
        }
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements 
        ///     the <see cref="T:System.Web.IHttpHandler"></see> interface.
        /// </summary>
        /// <param name="context">
        /// An <see cref="T:System.Web.HttpContext"></see> object that provides references 
        ///     to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.
        /// </param>
        public void ProcessRequest(HttpContext context)
        {
            if (!Security.IsAuthorizedTo(Rights.ViewPublicPosts))
            {
                context.Response.StatusCode = 401;
                return;
            }

            var title = RetrieveTitle(context);
            var format = RetrieveFormat(context);
            var list = GenerateItemList(context);
            list = CleanList(list);

            if (string.IsNullOrEmpty(context.Request.QueryString["post"]))
            {
                // Shorten the list to the number of posts stated in the settings, except for the comment feed.
                var max = Math.Min(BlogSettings.Instance.PostsPerFeed, list.Count);
                list = list.FindAll(item => item.IsVisible);

                list = list.GetRange(0, max);
            }

            SetHeaderInformation(context, list, format);

            if (BlogSettings.Instance.EnableHttpCompression)
            {
                CompressionModule.CompressResponse(context);
            }

            var generator = new SyndicationGenerator(BlogSettings.Instance, Category.Categories);
            generator.WriteFeed(format, context.Response.OutputStream, list, title);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements
        /// the <see cref="T:System.Web.IHttpHandler"></see> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"></see> object that provides references
        /// to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.
        /// </param>
        public void ProcessRequest(HttpContext context)
        {
            string              title  = RetrieveTitle(context);
            SyndicationFormat   format = RetrieveFormat(context);
            List <IPublishable> list   = GenerateItemList(context);

            list = CleanList(list);

            if (string.IsNullOrEmpty(context.Request.QueryString["post"]))
            {
                // Shorten the list to the number of posts stated in the settings, except for the comment feed.
                int max = Math.Min(BlogSettings.Instance.PostsPerFeed, list.Count);
                list = list.FindAll(delegate(IPublishable item)
                {
                    return(item.IsVisible == true);
                });

                list = list.GetRange(0, max);
            }

            SetHeaderInformation(context, list, format);

            if (BlogSettings.Instance.EnableHttpCompression)
            {
                HttpModules.CompressionModule.CompressResponse(context);
            }

            SyndicationGenerator generator = new SyndicationGenerator(BlogSettings.Instance, Category.Categories);

            generator.WriteFeed(format, context.Response.OutputStream, list, title);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetSyndicationFeed([FromRoute] string controller,
                                                             [FromHeader(Name = Constants.HeaderNames.Accept)]
                                                             string contentType, [FromFilter] Encoding encoding, [FromRoute] string ns, [FromRoute] ulong rs,
                                                             [FromQuery(Name = "q")] string query = default)
        {
            var mediaType = contentType?.ToLowerInvariant().Trim();
            var charset   = encoding.WebName;
            var queryUrl  = Request.GetEncodedUrl();

            var cacheKey = $"{mediaType}:{charset}:{queryUrl}";

            if (!Request.IsContentStale(cacheKey, _feeds, out var stream, out var lastModified, out var result))
            {
                return(result);
            }

            if (stream != default || _feeds.TryGetValue(cacheKey, out stream))
            {
                return(ServeFeed(cacheKey, stream, mediaType, charset, lastModified));
            }

            var(records, _) = await QueryAsync(controller, ns, rs, query, CancellationToken);

            if (!SyndicationGenerator.TryBuildFeedAsync(queryUrl, ns, rs, records, mediaType, encoding, out stream,
                                                        out lastModified))
            {
                return(new UnsupportedMediaTypeResult());
            }

            _feeds.Set(cacheKey, stream);
            _feeds.Set($"{cacheKey}:{HeaderNames.LastModified}", lastModified);

            return(ServeFeed(cacheKey, stream, mediaType, charset, lastModified));
        }
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements
        ///     the <see cref="T:System.Web.IHttpHandler"></see> interface.
        /// </summary>
        /// <param name="context">
        /// An <see cref="T:System.Web.HttpContext"></see> object that provides references
        ///     to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.
        /// </param>
        public void ProcessRequest(HttpContext context)
        {
            if (!Security.IsAuthorizedTo(Rights.ViewPublicPosts))
            {
                context.Response.StatusCode = 401;
                return;
            }

            var title  = RetrieveTitle(context);
            var format = RetrieveFormat(context);
            var list   = GenerateItemList(context);

            list = CleanList(list);

            if (string.IsNullOrEmpty(context.Request.QueryString["post"]))
            {
                // Shorten the list to the number of posts stated in the settings, except for the comment feed.
                var max = BlogSettings.Instance.PostsPerFeed;

                // usually we want to restrict number of posts for subscribers to latest
                // but it can be overriden in query string to bring any number of items
                if (!string.IsNullOrEmpty(context.Request.QueryString["maxitems"]))
                {
                    int maxItems;
                    if (int.TryParse(context.Request.QueryString["maxitems"], out maxItems))
                    {
                        max = maxItems;
                    }
                }

                list = list.FindAll(item => item.IsVisible).Take(Math.Min(max, list.Count)).ToList();
            }

            SetHeaderInformation(context, list, format);

            if (BlogSettings.Instance.EnableHttpCompression)
            {
                CompressionModule.CompressResponse(context);
            }

            var generator = new SyndicationGenerator(BlogSettings.Instance, Category.Categories);

            generator.WriteFeed(format, context.Response.OutputStream, list, title);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements
        ///     the <see cref="T:System.Web.IHttpHandler"></see> interface.
        /// </summary>
        /// <param name="context">
        /// An <see cref="T:System.Web.HttpContext"></see> object that provides references
        ///     to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.
        /// </param>
        public void ProcessRequest(HttpContext context)
        {
            var title  = RetrieveTitle(context);
            var format = RetrieveFormat(context);
            var list   = GenerateItemList(context);

            list = CleanList(list);

            // Sueetie Modified - Enter Rss Retrieval
            BlogCommon.FireAndForgetRecordBlogRss(new
                                                  SueetieBlogRss
            {
                ApplicationID = SueetieApplications.Current.ApplicationID,
                RemoteIP      = context.Request.UserHostAddress,
                UserAgent     = context.Request.UserAgent
            });

            if (string.IsNullOrEmpty(context.Request.QueryString["post"]))
            {
                // Shorten the list to the number of posts stated in the settings, except for the comment feed.
                var max = Math.Min(BlogSettings.Instance.PostsPerFeed, list.Count);
                list = list.FindAll(item => item.IsVisible);

                list = list.GetRange(0, max);
            }

            SetHeaderInformation(context, list, format);

            if (BlogSettings.Instance.EnableHttpCompression)
            {
                CompressionModule.CompressResponse(context);
            }

            var generator = new SyndicationGenerator(BlogSettings.Instance, Category.Categories);

            generator.WriteFeed(format, context.Response.OutputStream, list, title);
        }
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements 
        ///     the <see cref="T:System.Web.IHttpHandler"></see> interface.
        /// </summary>
        /// <param name="context">
        /// An <see cref="T:System.Web.HttpContext"></see> object that provides references 
        ///     to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.
        /// </param>
        public void ProcessRequest(HttpContext context)
        {
            if (!Security.IsAuthorizedTo(Rights.ViewPublicPosts))
            {
                context.Response.StatusCode = 401;
                return;
            }

            var title = RetrieveTitle(context);
            var format = RetrieveFormat(context);
            var list = GenerateItemList(context);
            list = CleanList(list);

            if (string.IsNullOrEmpty(context.Request.QueryString["post"]))
            {
                // Shorten the list to the number of posts stated in the settings, except for the comment feed.
                var max = BlogSettings.Instance.PostsPerFeed;
                
                // usually we want to restrict number of posts for subscribers to latest
                // but it can be overriden in query string to bring any number of items
                if (!string.IsNullOrEmpty(context.Request.QueryString["maxitems"]))
                {
                    int maxItems;
                    if (int.TryParse(context.Request.QueryString["maxitems"], out maxItems))
                        max = maxItems;
                }

                list = list.FindAll(item => item.IsVisible).Take(Math.Min(max, list.Count)).ToList();
            }

            SetHeaderInformation(context, list, format);

            if (BlogSettings.Instance.EnableHttpCompression)
            {
                CompressionModule.CompressResponse(context);
            }

            var generator = new SyndicationGenerator(BlogSettings.Instance, Category.Categories);
            generator.WriteFeed(format, context.Response.OutputStream, list, title);
        }