【问题标题】:Conditional GET ignored with fetch API使用 fetch API 忽略条件 GET
【发布时间】:2021-03-02 19:15:27
【问题描述】:

我正在使用 Discord.js/Node.js 获取和解析 RSS 提要 (https://www.mangaupdates.com/rss.php)。我目前正在尝试添加一个有条件的If-Modified-Since 标头来向RSS 提要发出一个有条件的GET 请求。这是我的代码:

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

响应状态始终为200,即使它应该仅在自调用fetch 命令时被修改后才发出请求。

【问题讨论】:

  • 这是否适用于 RSS 提要仅在有更新时获取

标签: javascript node.js http fetch-api if-modified-since


【解决方案1】:

即使请求的资源是最新的,Fetch API 也会在内部将 304 替换为 200。你对此无能为力。

查看Recognize HTTP 304 in service worker / fetch()

【讨论】:

  • 这似乎没有解决问题。它仍然输出 200。我还认为 fetch API documentationcache 默认为 no-store 如果 If-Modified-Since 设置为标题
猜你喜欢
  • 2021-02-24
  • 1970-01-01
  • 2011-01-27
  • 2021-11-18
  • 1970-01-01
  • 2022-03-22
  • 1970-01-01
  • 2018-05-22
  • 2015-05-20
相关资源
最近更新 更多