Issue with TIdHttp.Head() routine

Giganews Newsgroups
Subject: Issue with TIdHttp.Head() routine
Posted by:  Scott Bussinger (scot…@opto-pps.com)
Date: Fri, 30 Jun 2006

I just updated to the latest development snapshot of Indy 10 and I think
there's a problem with some changes in regards to TIdHttp.Head().

A change was made at some point to the TIdHTTPProtocol.ProcessResponse()
function. The code in question looks like:

    if LNeedAuth then begin
      // Read the content of Error message in temporary stream
      DiscardContent;
      Result := wnAuthRequest;
    end else begin
      if (Request.Method = Id_HTTPMethodHead) or (LResponseCode = 204) then
begin
        // Have noticed one case where a non-conforming server did send an
        // entity body in response to a HEAD request, so just ignore
anything
        // the server may send by accident
        DiscardContent(5000); // Lets wait 5 seconds for any kind of content
      end else begin
        FHTTP.ReadResult(Response);
      end;
      Result := wnJustExit;
    end;

In case of TIdHttp.Head(), the DiscardContent(5000) call is always made
which looks like this:

  procedure DiscardContent(AUnexpectedContentTimeout: Integer =
IdTimeoutDefault);
  var
    LTempResponse: TIdStringStream;
    LTempStream: TIdStream;
  begin
    LTempResponse := TIdStringStream.Create('');
    LTempStream := Response.ContentStream;
    Response.ContentStream := LTempResponse;
    try
      FHTTP.ReadResult(Response, AUnexpectedContentTimeout);
    finally
      Response.ContentStream := LTempStream;
      Sys.FreeAndNil(LTempResponse);
    end;
  end;

This routine will under normal circumstances now generate a timeout
exception and this exception is allowed to bubble up to the original calling
routine. So if you have any code that calls Head() you will now get an
EIdReadTimeout exception that you never got before. In my case this caused
the routine to abort every time I ran it.

Just about as bad, if I put a try...except...end around the call to Head()
to mask the issue, then every call to Head() takes a minimum of 5 seconds
while it waits for the timeout to occur (actually if I counted off the
seconds it seemed to take longer than that for reasons that weren't clear to
me).

Any thoughts on the best way to fix this? It's not clear to me why that
DiscardContent stuff was added in the first place.

Replies