0

control:no-cache` field into my request when requesting RSS feed

I cant quit figure what values should i put in In case of Content-type it works well but it refuses to add correctly Cachce-Control

code :

options =  {uri :SUPPORT_FEED_URI,
            headers : {
                       'Content-Type': 'application/x-www-form-urlencoded',
                       'Cache-Control': 'no-cache'
                       },
            }

request.get(options)
                .on('error', (err) => { reject(err); })
                .pipe(feedparser)
                .on('end', () => { return resolve(items); });

What i get in request headers :

Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:cache-control  <-- doesnt seems to be right Want something like Cache-Control : no-cache
Access-Control-Request-Method:GET
Connection:keep-alive
Host: xxxx.yyyy.zz
Origin:http://127.0.0.1:8888
Referer:http://127.0.0.1:8888/webconsole/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
content-type:application/x-www-form-urlencoded
Ziker
  • 877
  • 2
  • 10
  • 30

2 Answers2

1

Your capture is a CORS pre-flight (OPTIONS) request as the URL is on a different domain or considered to be different-origin.

Such a request will not include custom headers, they are added to Access-Control-Request-Headers instead to see if the destination server will allow them.

If the destination server responds with an acceptable allow- response the subsequent GET will include your header.

Alex K.
  • 171,639
  • 30
  • 264
  • 288
0

Depends what you are trying to achieve.

If you are trying to force a non-cached response and dont have control over the server, one thing you can do is to add a fake query param like this.

options =  {
    uri :`${SUPPORT_FEED_URI}?${new Date().getTime()}`,
    headers : {
        'Content-Type': 'application/x-www-form-urlencoded'
    },
}

For more information on the 'Cache-Control' header see the top answer here. What's the difference between Cache-Control: max-age=0 and no-cache?

Community
  • 1
  • 1
Thomas Powell
  • 115
  • 1
  • 12