Proxy support in TIdHTTP?

Giganews Newsgroups
Subject: Proxy support in TIdHTTP?
Posted by:  Jonny Bergdahl (jonny.bergdahl.nospam@edicom.se)
Date: Fri, 6 Feb 2004

I am having a problem passing HTTP traffic through a Microsoft ISA Server,
and need some help. I have configured the ISA Server to allow Basic
authentication (which it does not do by default).

I create the object in code like this:
--- Code snippet ----
  _objHTTP:=TIdHTTP.Create(nil);
  _objHTTP.Intercept:=_objLogger;
  _objHTTP.OnStatus:=OnStatus;
  _objHTTP.OnWork:=OnWork;
  _objHTTP.HandleRedirects:=True;
  _objHTTP.ReadTimeout:=30000;
  _objHTTP.AuthRetries:=3;
----------------------

Then I set up proxy support like this:
--- Code snippet ----
    if _strProxyServer<>'' then
      begin
        DebugStr('Setting up proxy server');
        _objHTTP.ProtocolVersion:=pv1_0;
        _objHTTP.ProxyParams.ProxyServer:=_strProxyServer;
        _objHTTP.ProxyParams.ProxyPort:=_intProxyPort;
        if (_strProxyUsername<>'') then
          begin
            _objHTTP.ProxyParams.BasicAuthentication:=True;
            _objHTTP.ProxyParams.ProxyUsername:=_strProxyUsername;
            _objHTTP.ProxyParams.ProxyPassword:=_strProxyPassword;
          end;
      end;
------------------

I have used a packet sniffer to see whats going on. The request is sent to
the proxy server, which replies with the result code 407, authentication
required. No more traffic is sent, which means that it does not retry. What
am I doing wrong?

Also; I would like to support the Digest and NTLM autentication methods, but
I can't seem to get it to work. Can someone please post a small example
showing how it is supposed to work?

During testing I found a bug in the code of
TIdCustomHTTP.DoOnProxyAuthorization:
--------------
    begin
      S := AResponse.ProxyAuthenticate[i];
      try
        Auth := FindAuthClass(Fetch(S));
        break;
      except
      end;
    end;

--------------
The author obviously thought that the FindAuthClass() function would throw
an exception if no class was found. However, that code looks like this:
--------------
begin
  if AuthList.IndexOf(AuthName) = -1 then
    result := nil
  else
    result :=
TAuthListObject(AuthList.Objects[AuthList.IndexOf(AuthName)]).Auth;
end;
--------------
This means that Auth is set to nil causing an access violation on the
following line:
-------------
    ProxyParams.Authentication := Auth.Create;
-------------

Regards;
/jb

Replies