Bug in TIdHTTPResponseInfo.SetHeaders when AuthRealm is defined and content is not

Giganews Newsgroups
Subject: Bug in TIdHTTPResponseInfo.SetHeaders when AuthRealm is defined and content is not
Posted by:  jgv (jacques.garciavazqu…@telenet.be)
Date: Sun, 7 Feb 2010

Hi All,

There is a problem in headers when AuthRealm is not empty and a content
has not been defined. In this case you assign a content but after the
content-length header is already set to zero in the inherited part.

I have modified this part by forcing the content length:

if AuthRealm <> '' then {Do not Localize}
begin
  ResponseNo := 401;
  Values['WWW-Authenticate'] := 'Basic realm="' + AuthRealm + '"';
  {Do not Localize}
  if (Length(FContentText) = 0) and not Assigned(FContentStream) then
  begin
    Values['Content-Type'] := 'text/html';    {Do not Localize}
    FContentText := '<HTML><BODY><B>' + IntToStr(ResponseNo) + ' ' +
                    RSHTPUnauthorized + '</B></BODY></HTML>';
                    {Do not Localize}

    //-- jgv add this
    Values['Content-Length'] := IntToStr (Length (fcontentText));
  end;
end;

Alternativelly we can solve this problem by assigning a content but I
think it is better to correctly provide the original behavior.

Regards
Jacques

Replies