Sitecore – IMS (If-Modified-Since) request header for Media Items

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.

  1. 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. .
  2. Override the Sitecore implementation to compare the dates in MediaRequestHeader
  3. Open a ticket with Sitecore to check if they have any patch for it

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s