问题
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