* * *

Author Topic: idHTTPProxyServer through another Http proxy  (Read 1216 times)

RDL

  • New member
  • *
  • Posts: 33
idHTTPProxyServer through another Http proxy
« on: April 05, 2018, 10:44:05 am »
Good day.

It is not possible to redirect requests to another proxy server.

Code: Pascal  [Select]
  1. procedure TfrmMain.IdHTTPProxyServerHTTPBeforeCommand(AContext: TIdHTTPProxyServerContext);
  2. var
  3. tProxy: TIdCustomTransparentProxy;
  4. begin
  5. tProxy:=TIdCustomTransparentProxy.Create(AContext.Connection);
  6. tProxy.Host:='127.0.0.1';
  7. tProxy.Port:=8888;
  8. tProxy.Enabled:=true;
  9. AContext.Connection.Socket.TransparentProxy:=tProxy;
  10. end;

I need through http (get, post).
I know how to redirect requests using the "Connect" method, but it does not work with all proxy servers.

I need your help.  :-[
Sorry for my english, google translation!

Remy Lebeau

  • Sr. Member
  • ****
  • Posts: 464
    • Lebeau Software
Re: idHTTPProxyServer through another Http proxy
« Reply #1 on: April 10, 2018, 07:41:42 pm »
It doesn't work because you are setting it up the wrong way.

TIdCustomTransparentProxy is an abstract base class, do not instantiate it directly.  You need to use a descendant instead (TIdSocksInfo for a SOCKS proxy, TIdConnectThroughHttpProxy for an HTTP proxy, etc).

But more importantly, you are attaching the TransparentProxy to the wrong TCP connection.  'AContext.Connection' is the existing established TCP connection with the client that connected to TIdHTTPProxyServer.  To pass that client's traffic with the target server through another proxy, you need to attach the TransparentProxy to 'AContext.OutboundClient' instead.

Try something more like this:

Code: [Select]
procedure TfrmMain.IdHTTPProxyServerHTTPBeforeCommand(AContext: TIdHTTPProxyServerContext);
var
  tProxy: TIdConnectThroughHttpProxy;
begin
  AContext.OutboundClient.CreateIOHandler;
  tProxy := TIdConnectThroughHttpProxy.Create(AContext.OutboundClient.IOHandler);
  tProxy.Host := '127.0.0.1';
  tProxy.Port := 8888;
  tProxy.Enabled := true;
  AContext.OutboundClient.Socket.TransparentProxy := tProxy;
end;
« Last Edit: April 10, 2018, 07:44:33 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus