开发者

Indy's TIdHTTPProxyServer: How to filter requests?

开发者 https://www.devze.com 2023-02-04 19:30 出处:网络
I\'m using an TIdHTTPProxyS开发者_如何学Pythonerver 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 ac

I'm using an TIdHTTPProxyS开发者_如何学Pythonerver 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!


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.


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.

0

精彩评论

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