javascriptnode.jshttpfetch-apiif-modified-since

Conditional GET ignored with fetch API


I am fetching and parsing an RSS feed (https://www.mangaupdates.com/rss.php) with Discord.js/Node.js. I'm currently trying to add a conditional If-Modified-Since header to make a conditional GET request to the RSS feed. Here is my code:

fetch(mangaUpdatesRSS, {
  method: 'GET',
  headers: {'If-Modified-Since': new Date().toUTCString()}
})
.then(res => {
  console.log(res.status);

The response status is always 200 even though it should only be making a request if it's been modified since the time of the fetch command is called.


Solution

  • Fetch API replaces 304 with 200 internally even if the requested resource is up to date. There's nothing you can do about it.

    Check out Recognize HTTP 304 in service worker / fetch()