We recently had an issue related to media item response status. While a CDN service was making a request to access Sitecore Media item and current date is passed in if-modified-since request header, response status code was always 200. However requested media items were not modified since a long time and response status code should be 304. To troubleshoot this issue when I explore the Sitecore code (MediaRequestHeader) , found that Sitecore has exact match logic to compare the “If-Modified-Since” with media item modified date. It means if a media item is modified lets say on “01/01/2018 01:00:00 PM” and request header has value “If-Modified-Since:Mon, 01 Jan 2018 01:00:00” it will give 304 status code. Any request which has any other date or time will always respond with 200 status code.
To fix this issue there are multiple approaches and choice can be based on your project condition.
- While CDN is making a call to Sitecore server for media item , it should pass the last modified date of file which CDN received as response on first request. .
- Override the Sitecore implementation to compare the dates in MediaRequestHeader
- Open a ticket with Sitecore to check if they have any patch for it