Hi, when using TIdHTTP with proxy there is exception generated when authorization was needed.
Exception EIdHTTPProtocolException is fired with some params, but I think that this procedure contains some bugs:
1. you can not have exception and not discard content from response at the same time
2. it fills this exception with empty information for response text and third parameter as well
So my code fix proposition is as follows:
Thanks, NevTon.
Exception EIdHTTPProtocolException is fired with some params, but I think that this procedure contains some bugs:
1. you can not have exception and not discard content from response at the same time
2. it fills this exception with empty information for response text and third parameter as well
So my code fix proposition is as follows:
Code:
function TIdHTTPProtocol.ProcessResponse(AIgnoreReplies: array of Int16): TIdHTTPWhatsNext;
var
LResponseCode, LResponseDigit: Integer;
procedure CheckException;
var
i: Integer;
LTempStream: TMemoryStream;
LOrigStream: TStream;
LRaiseException: Boolean;
LDiscardContent: Boolean;
LTempString: String;
begin
LRaiseException := True;
LDiscardContent := not (hoWantProtocolErrorContent in FHTTP.HTTPOptions);
if hoNoProtocolErrorException in FHTTP.HTTPOptions then begin
LRaiseException := False;
end
else if High(AIgnoreReplies) > -1 then begin
for i := Low(AIgnoreReplies) to High(AIgnoreReplies) do begin
if LResponseCode = AIgnoreReplies[i] then begin
LRaiseException := False;
LDiscardContent := not (hoWantProtocolErrorContent in FHTTP.HTTPOptions);
Break;
end;
end;
end;
LTempString := '';
LTempStream := Nil;
if {LRaiseException or} LDiscardContent then begin
LTempStream := TMemoryStream.Create;
LOrigStream := Response.ContentStream;
Response.ContentStream := LTempStream;
end else begin
LOrigStream := Nil;
end;
try
try
try
FHTTP.ReadResult(Request, Response);
except
on E: Exception do begin
FHTTP.Disconnect;
if not (E is EIdConnClosedGracefully) then begin
raise;
end;
end;
end;
if LRaiseException then begin
if LTempStream <> Nil then begin
LTempStream.Position := 0;
LTempString := ReadStringAsCharset(LTempStream, Response.CharSet);
end;
//
raise EIdHTTPProtocolException.CreateError(LResponseCode, Response.ResponseText, LTempString);
end;
finally
if {LRaiseException or} LDiscardContent then begin
Response.ContentStream := LOrigStream;
end;
end;
finally
if LDiscardContent then begin
LTempStream.Free;
end;
end;
end;
...
Thanks, NevTon.