简体   繁体   中英

node.js how to handle intentionally large (and bad) http requests

I'm working out on a few projects using node and each line of code that I write spans lots of ideas of how could someone destroy my node process.

Right now I'm thinking of this:

require('http').createServer(function(req, res)) {
    //DEAL WITH REQUEST HERE
  }.listen(port, net);

That's standard code for setting up a server and dealing with requests.

Let's say that I want to bring down that node process, I could send POST requests with loads of data on them and node.js would spend lots of time (and bandwith) on receiving all of them.

Is there a way to avoid this?

PHP Pros: How do you normally deal with this?

Is there a way to tell node or php (maybe apache) to just ignore requests from certain IPs ?

You can limit the http request size. Here is the middleware you can use.

https://github.com/senchalabs/connect/blob/master/lib/middleware/limit.js

http://www.senchalabs.org/connect/middleware-limit.html

PS Possibility duplication from maximum request lengths in node.js

For getting the IP address in node.js, you can try request.connection.remoteAddress .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM