Curl will not return when executing a HEAD request

I create resources on the node server and bind ETag to each of them. I am using the method found in this question What encoding should I use to correctly generate cryptography ETag in nodeJS? to generate ETags. However, when I make a HEAD request at the command line using curl, for example:

 $ curl -i -u username:password -X HEAD http://localhost:3000/aResource/0 

answer

 HTTP/1.1 200 OK X-Powered-By: Express ETag: "1a37c148692f92ad6c97887f77c873e6" Content-Type: text/plain Date: Sat, 26 Oct 2013 01:06:28 GMT Connection: keep-alive ^C $ 

and I have to specifically press Control-C to see the command line again. On the other hand, I find this strange, because the way the HEAD request is processed is through app.head on the node, and after authentication I call the function:

 function serveResourceEtag(req, res) { console.log("Following route through HEAD"); var anID = parseInt(req.params[resourceID], "utf8"); if (anID < serverData.resourceEtags.length) { res.writeHead (200, {"ETag": "\"" + serverData.resourceEtags[anID] + "\"", "Content-Type": "text/plain"}); res.end(); } else { res.writeHead (404, {"Content-Type": "text/plain"}); res.end(); } }; 

In other words, although I have res.end (); the team in the end, the transfer for some reason did not stop. As far as I understand, the HEAD request should have the same header as the GET request. The difference with a GET is that in the case of HEAD we do not have a GET request body. Can you say that this is a problem?

+6
source share
2 answers

You are right about the behavior of HTTP methods, this is just the curl you need:

 curl -I -u username:password http://localhost:3000/aResource/0 

not -X HEAD, which says, uses the HTTP HEAD method, not GET, which returns only headers

+7
source

This is not your server error. When I do curl -i -X HEAD http://google.com , I need to kill the curl to get back to the hint, which is odd, because the GET swirl request really brings me back to the prompt.

+1
source

Source: https://habr.com/ru/post/956768/


All Articles