开发者

Restrict servlet response

开发者 https://www.devze.com 2023-04-07 11:03 出处:网络
I have a web server which has lot of hits f开发者_如何学Crom automated machines. Those machine sends their status on web server to store in db. Some of hits are useless so I want to avoid those reques

I have a web server which has lot of hits f开发者_如何学Crom automated machines. Those machine sends their status on web server to store in db. Some of hits are useless so I want to avoid those request's responses because those useless responses generate lot of traffic on network. My question is that "How to restrict servlet response for unwanted traffic."


I'd return a sensible HTTP 4xx client error. Which one to choose depends on the "uselessness" of those requests.

If those requests are bad because of for example missing parameters, return HTTP 400 Bad Request.

response.sendError(HttpServletResponse.SC_BAD_REQUEST);

If those requests are forbidden due to improper authorization, return HTTP 403 Forbidden.

response.sendError(HttpServletResponse.SC_FORBIDDEN);

If the client is smart enough, they will get logged and the responsible admin/developer should look into it and eventually fix it. This is a win-win sitution.


Your servlet is not forced to return anything if you don't want to. If you do not return a response, the connection will be closed and no traffic will be generated.

By the way, depending on your scenario, it could be possible to keep a long-lasting HTTP connection between the client (automated machines) and the web server. This way you do not need to open a new connection for each request and you can save some bytes, if the higher complexity is worth it.


First you should try to avoid these request, try an exclusion file in your server. If that does not work, just send a forbidden (403 status) as response for requests you identified as "useless" - normally by scanning the user agent header for specific bots.

0

精彩评论

暂无评论...
验证码 换一张
取 消