Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

javascript - 在服务人员内部读取请求标头(Reading request headers inside a service worker)

I've created a very basic service worker, that logs the request headers on fetch event:

(我创建了一个非常基本的服务工作程序,该事件记录了fetch事件时的请求头:)

self.addEventListener('fetch', event => {
  console.log("- Fetch -");
  for (const pair of event.request.headers.entries()) {
    console.log(pair[0]+ ': '+ pair[1]);
  }
});

On the main page, I'm fetching the same page like so:

(在主页上,我这样提取同一页面:)

function fetchPage() {
   fetch(location.href);
}

When logging the headers I'm getting just the following 2 headers:

(记录标题时,我只会得到以下2个标题:)

- Fetch -
service-worker.js:12 accept: */*
service-worker.js:12 user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36

Why can't I see any other/custom headers?

(为什么看不到其他/自定义标题?)


Is it a security limitation?

(这是安全限制吗?)

  ask by Shlomi Schwartz translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...