3

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!

TheNewbie
  • 564
  • 2
  • 6
  • 13

2 Answers2

3

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.

jachguate
  • 16,976
  • 3
  • 57
  • 98
  • Your answer made me realize I had been using an old version of Indy. It has improved a lot, at least the parts I checked. – TheNewbie Jan 13 '11 at 05:58
1

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.

  • -1: OnConnect will fire when the HTTP **client** connects to your proxy, not when the proxy connects to the remote server (that's up to you, TidHTTPProxy does not implement it), and no URL is still available. Unless you're only checking which "internal" IPs are allowed to send HTTP requests outside, that's not the correct way. –  Jan 12 '11 at 13:45
  • @ldsandon: `TIdHTTPProxyServer` does implement connections to the remote server for you (otherwisee it would not be much of a proxy). See the `TIdHTTPProxyServerContext.OutboundClient` property. – Remy Lebeau Jan 12 '11 at 21:32
  • @Remy Lebeau: you're right, I got confused with a proxy implementation I did some time ago using only TidHTTPServer. –  Jan 14 '11 at 19:25