问题
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:
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()
来源:https://stackoverflow.com/questions/64911396/conditional-get-ignored-with-fetch-api