Conditional GET ignored with fetch API

526 Views Asked by At

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.

1

There are 1 best solutions below

1
Siddharth Subramanian On BEST ANSWER

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()