Conditional GET ignored with fetch API

喜你入骨 提交于 2021-02-11 15:06:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!