0

I have a simple node server. All it does is log the req.headers and res (I am learning!).

let http = require('http'); function handleIncomingRequest(req, res) { console.log('---------------------------------------------------'); console.log(req.headers); console.log('---------------------------------------------------'); console.log(); console.log('---------------------------------------------------'); res.writeHead(200, {'Content-Type': 'application/json'}); res.end(JSON.stringify( {error: null}) + '\n'); } let s = http.createServer(handleIncomingRequest); s.listen(8080); 

When I use curl to test the server it sends 1 request. When I use chrome it sends 2 different requests.

 { host: 'localhost:8080', connection: 'keep-alive', 'cache-control': 'max-age=0', 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'accept-encoding': 'gzip, deflate, sdch, br', 'accept-language': 'en-GB,en;q=0.8' } 

and

{ host: 'localhost:8080', connection: 'keep-alive', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', accept: 'image/webp,image/*,*/*;q=0.8', referer: 'http://localhost:8080/', 'accept-encoding': 'gzip, deflate, sdch, br', 'accept-language': 'en-GB,en;q=0.8' } 

This is in incognito mode as in normal mode there are 3 requests! What is the browser doing and why?

3
  • Are you testing this with a website? Because in this case it may be the request of an embedded image, css-file, script etc. The browser automatically sends separate http-requests to fetch these resources. Commented Mar 2, 2017 at 7:48
  • No website. I added the server code. Commented Mar 2, 2017 at 8:23
  • How exactly do you send your request in chrome? Commented Mar 2, 2017 at 8:24

1 Answer 1

1

Hard to tell without seeing the full transaction data (for example, what was the request, i.e. what came after GET or POST - and what were the answers from the server).

But it could be caused by the 'upgrade-insecure-requests': '1' header:

When a server encounters this preference in an HTTP request’s headers, it SHOULD redirect the user to a potentially secure representation of the resource being requested.

See this.


accept: 'image/webp,image/*,*/*;q=0.8' 

On the other hand, the second request is probably for an image only, most likely the favicon.ico or a (bigger) icon for iPad/iPhone maybe (that could explain the 3 requests). You should check out the full request data to be sure.

You can use F12 en select network in the browser to see what's really happening.

Sign up to request clarification or add additional context in comments.

1 Comment

Reading through the whole req data it seems you are correct about the favicon.ico request. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.