Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TIdHttp no ResponseContent on bad request
#1
Wink 
Hello,

1.
with the TIdHTTP i has problems on Rest- Server. Sends the Server on Bad Request (400, 404) the Client doesn’t received the ResponseContent.

I look and found a little workaround. 

I advanced IdHttp.pas

Definition:
TIdCustomHTTP = class(TIdTCPClientCustom)
private
  FRestMode: Boolean;  //Add
  procedure SetRestMode(AValue: Boolean);  //Add

public
  property RestMode: Boolean read FRestMode write SetRestMode; //Add 


Implementation:
procedure TIdCustomHTTP.SetRestMode(AValue: Boolean); //Add
begin
  if FRestMode=AValue then Exit;
  FRestMode:=AValue;
  if FRestMode then begin
    HTTPOptions:= HTTPOptions + [hoNoProtocolErrorException];
  end else begin
    HTTPOptions:= HTTPOptions - [hoNoProtocolErrorException];
  end;
end;

function TIdHTTPProtocol.ProcessResponse(AIgnoreReplies: array of Int16): TidHTTPWhatsNext;

else begin  //From case
  if not FHttp.FRestMode then begin //Add
    CheckException;
    Result := wnJustExit;
    Exit;
  end; //Add
end;

maybe that will help the users too Wink


2.
I have seen, you're working on Indy OpenSSL 1.1.1, very nice, thanks.

My question. When will the new Indy library be added to the Lazarus library.


Thanks for support.
Reply
#2
(09-14-2021, 07:33 PM)fpctuxe Wrote: with the TIdHTTP i has problems on Rest- Server. Sends the Server on Bad Request (400, 404) the Client doesn’t received the ResponseContent.

Yes, it does, just not where you are expecting it to be.

By default, TIdHTTP raises an EIdHTTPProtocolException for any HTTP error, where the response content will be in the EIdHTTPProtocolException.ErrorMessage property.

As you have already noted, you can enable the hoNoProtocolErrorException option to avoid this exception. There is also a hoWantProtocolErrorContent option available, which you seem to have missed (see https://www.indyproject.org/2016/01/10/n...ved-event/).

(09-14-2021, 07:33 PM)fpctuxe Wrote: I look and found a little workaround. 

That workaround is not necessary, and I will not be incorporating something like that into the main code. The same effect can be achieved by simply enabling the hoNoProtocolErrorException and hoWantProtocolErrorContent options together. No need to modify ProcessResponse() at all.

(09-14-2021, 07:33 PM)fpctuxe Wrote: When will the new Indy library be added to the Lazarus library.

Indy has been available in Lazarus' Online Package Manager for awhile, and is kept up-to-date with GIT updates.

Reply
#3
1.
I have tested with the HttpOptions hoNoProtocolErrorException and hoWantProtocolErrorContent

It works on rest- server as required. This is the better way. Thanks.



2.
In the Lazarus Online Package Manager is currently the version 10.6.2.3911.

Is in this version OpenSSL 1.1.1 integrated?
Reply
#4
(09-15-2021, 05:55 PM)fpctuxe Wrote: In the Lazarus Online Package Manager is currently the version 10.6.2.3911.

Is in this version OpenSSL 1.1.1 integrated?

No, because that new code has not been incorporated into Indy's main code yet, it is still a Work-In-Progress.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)