在命令行上,我可以执行如下的请求: curl -I -H“快速调试: 1”
它将从为该URL提供服务的CDN返回许多有用的信息,在本例中,快速:
cache-control: public, max-age=0, must-revalidate
last-modified: Tue, 20 Apr 2021 21:17:46 GMT
etag: "4c5cb3eb0ddb001584dad329b8727a9a"
content-type: text/html
server: AmazonS3
surrogate-key: /v3.6/tutorial/nav/alerts-and-monitoring/
accept-ranges: bytes
date: Fri, 30 Apr 2021 20:50:15 GMT
via: 1.1 varnish
age: 0
fastly-debug-path: (D cache-lga21923-LGA 1619815815) (F cache-lga21940-LGA 1619815815)
fastly-debug-ttl: (M cache-lga21923-LGA - - 0)
fastly-debug-digest: 04c3e527819b6a877de6577f7461e132b97665100a63ca8f667d87d049092233
x-served-by: cache-lga21923-LGA
x-cache: MISS
x-cache-hits: 0
x-timer: S1619815815.944515,VS0,VE136
vary: Accept-Encoding
content-length: 65489我如何在节点中做到这一点?
这是我的尝试:
const headers = {
'Fastly-Key': environment.getFastlyToken(),
'Accept': 'application/json',
'Content-Type': 'application/json',
'Fastly-Debug': 1
};
async retrieveSurrogateKey(url) {
console.log("this is the url: ", url)
try {
request({
method: `GET`,
url: url,
headers: headers,
}, function(err, response, body) {
if (err){
console.trace(err)
}
console.log(request.headers)
})
} catch (error) {
console.log("error in retrieval: ", error)
}
}有什么办法让我传递-I和-H标志吗?
发布于 2021-04-30 22:51:04
-H (标头)标志允许您在cURL中指定自定义标头。你的代码已经做到了-太棒了!剩下的就是模仿-I (head)标志。
从cURL手册中获取-I选项:
只获取标头!HTTP-服务器具有命令头的特性,它只用于获取文档的标题。
要使用HEAD方法,需要指定它而不是GET:
method: `HEAD`最后,服务器在响应中返回的头可以从response.headers获得。
https://stackoverflow.com/questions/67340394
复制相似问题