简体   繁体   English

Curl HEAD 请求返回最后修改的 header 但节点 https.request(..., {method: HEAD},...) 没有

[英]Curl HEAD request returns a last-modified header but Node https.request(..., {method: HEAD},...) does not

Apparently there's something I don't know about HEAD requests.显然我对 HEAD 请求有些不了解。

Here's the URL: 'https://theweekinchess.com/assets/files/pgn/eurbli22.pgn', which I'll refer to as <URL> below.这是 URL:“https://theweekinchess.com/assets/files/pgn/eurbli22.pgn”,我在下面将其称为 <URL>。

If I curl this, I see a last-modified entry in the headers:如果我输入 curl 这个,我会在标题中看到最后修改的条目:

curl --head <URL> curl --head <网址>

HTTP/2 200 
last-modified: Sun, 18 Dec 2022 18:07:16 GMT
accept-ranges: bytes
content-length: 1888745
host-header: c2hhcmVkLmJsdWVob3N0LmNvbQ==
content-type: application/x-chess-pgn
date: Wed, 11 Jan 2023 23:09:14 GMT
server: Apache

But if I make a HEAD request in Node using https, That information is missing:但是,如果我使用 https 在 Node 中发出 HEAD 请求,则缺少该信息:

  https.request(<URL>, { method: 'HEAD' }, res => {
            console.log([<URL>, res.headers])}).end()

This returns:这将返回:

 [
  <URL>
  {
    date: 'Wed, 11 Jan 2023 23:16:15 GMT',
    server: 'Apache',
    p3p: 'CP="NOI NID ADMa OUR IND UNI COM NAV"',
    'cache-control': 'private, must-revalidate',
    'set-cookie': [
      'evof3sqa=4b412b5913b38669fc928a0cca9870e4; path=/; secure; HttpOnly'
    ],
    upgrade: 'h2,h2c',
    connection: 'Upgrade, Keep-Alive',
    'host-header': 'c2hhcmVkLmJsdWVob3N0LmNvbQ==',
    'keep-alive': 'timeout=5, max=75',
    'content-type': 'text/html; charset=UTF-8'
  }
]

I tried axios instead of https:我尝试使用 axios 而不是 https:

  const response = await axios.head('https://theweekinchess.com/assets/files/pgn/eurbli22.pgn');
  console.log({response: response.headers})

And that works (incl. the proper MIME type):这有效(包括正确的 MIME 类型):

date: 'Thu, 12 Jan 2023 20:00:48 GMT',
server: 'Apache',
upgrade: 'h2,h2c',
connection: 'Upgrade, Keep-Alive',
'last-modified': 'Sun, 18 Dec 2022 18:07:16 GMT',
'accept-ranges': 'bytes',
'content-length': '1888745',
'host-header': 'c2hhcmVkLmJsdWVob3N0LmNvbQ==',
'keep-alive': 'timeout=5, max=75',
'content-type': 'application/x-chess-pgn'

I also tried waiting for re2.on('end', console.log(res.headers)), but same output as before.我也尝试等待 re2.on('end', console.log(res.headers)),但与之前相同的 output。

I'm going to close this issue and post it instead as a 'bug' on Node's site.我将关闭此问题并将其作为“错误”发布到 Node 的站点上。 I'm sure there's something that needs to be changed in how I'm executing the HEAD request.我确定我执行 HEAD 请求的方式需要更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM