Skip to content

Commit 34557a7

Browse files
committed
If the category does not exist do not return any data. This prevents injecting user data in the rss category title if it does not exist. Also prevents caching of data unnecessarily.
1 parent 9bbd2a6 commit 34557a7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

source/DasBlog.Web.UI/Controllers/FeedController.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,27 @@ public IActionResult Rss()
4141
memoryCache.Set(CACHEKEY_RSS, rss, SiteCacheSettings());
4242
}
4343

44-
logger.LogInformation(new EventDataItem(EventCodes.RSS, null, "RSS request"));
45-
4644
return Ok(rss);
4745
}
4846

4947
[Produces("text/xml")]
5048
[HttpGet("feed/rss/{category}"), HttpHead("feed/rss/{category}")]
5149
public IActionResult RssByCategory(string category)
5250
{
53-
5451
if (!memoryCache.TryGetValue(CACHEKEY_RSS + "_" + category, out RssRoot rss))
5552
{
5653
rss = subscriptionManager.GetRssCategory(category);
5754

58-
memoryCache.Set(CACHEKEY_RSS + "_" + category, rss, SiteCacheSettings());
55+
if (rss.Channels[0]?.Items?.Count > 0)
56+
{
57+
memoryCache.Set(CACHEKEY_RSS + "_" + category, rss, SiteCacheSettings());
58+
}
5959
}
6060

61-
logger.LogInformation(new EventDataItem(EventCodes.RSS, null, "RSS category request: '{0}'", category));
61+
if(rss.Channels[0]?.Items?.Count == 0)
62+
{
63+
return NoContent();
64+
}
6265

6366
return Ok(rss);
6467
}
@@ -106,8 +109,6 @@ public async Task<IActionResult> BloggerPost()
106109
logger.LogError(new EventDataItem(EventCodes.RSS, null, "FeedController.BloggerPost Error: {0}", ex.Message));
107110
}
108111

109-
logger.LogInformation(new EventDataItem(EventCodes.RSS, null, "FeedController.BloggerPost successfully submitted"));
110-
111112
BreakSiteCache();
112113

113114
return Content(blogger);

0 commit comments

Comments
 (0)