Node.js: curl: (52) An empty response from the server with a space in the request not encoded

var http = require('http'); var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello World\n"); }); server.listen(8000); console.log("Server running at http://127.0.0.1:8000/"); 

I ran the following curl commands:

 curl "http://127.0.0.1:8000/" Hello World // space is not encoded curl "http://127.0.0.1:8000/xy" curl: (52) Empty reply from server curl "http://127.0.0.1:8000/x" Hello World // space is encoded curl "http://127.0.0.1:8000/x%20y" Hello World 

Could you explain why I get curl?

In this case, I want to send 500 back. Can I do it?

+6
source share
2 answers

Even with the missing res.send it looks like a problem with your route. you probably meant.

 app.get('/item/:id', function(...) { .. }) 

Pay attention to : before id . This creates a variable that can be accessed at req.params.id.

+1
source

I also have this question. I think curl expects an already encoded url if it is quoted with double quotes. If it finds a space in the URL, it will consider it invalid.

And this is very different from the wget command. If you run this:

 wget "http://127.0.0.1:8000/xy" 

Actually wget encodes the url for you and the request will really be sent as:

 http://127.0.0.1:8000/x%20y 

These facts really tease our brains.

0
source

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


All Articles