Indy's TIdHTTPProxyServer: How to filter requests?

风流意气都作罢 提交于 2019-12-05 02:06:29

问题


I'm using an TIdHTTPProxyServer to implement a simple HTTP proxy, but I'd like now to block some connections if they match certain URLs. Which event and/or component is best to accomplish that? Indy documentation is not too explicative. :(

Thanks!


回答1:


As a basic filter you can use the OnHTTPBeforeCommand event handler (which fires before the command is sent to the HTTP server).

Inspect the Context parameter properties, you'll find useful:

Context.Command
Context.OutboundClient.Host
Context.OutboundClient.Port
Context.Document
Context.Headers

I never tried to stop the PassTrough at this time, but I bet you can do it by just raising an exception at that point if you determine there's a block rule match.




回答2:


the component has a "OnConnect" event, double-click it and add this code:

if AContext.Connection.Socket.Binding.PeerIP = '127.0.0.1' then
  AContext.Connection.Disconnect;

replace 127.0.0.1 with your filter, this is just a "extremely basic example", same applies to other Indy servers which have a "OnConnect" event.



来源:https://stackoverflow.com/questions/4666773/indys-tidhttpproxyserver-how-to-filter-requests

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!