Most servers close connections after a short request timeout,
that may happen even after a request has been successfully sent.  
Currently THttpCli doesn't handle this case properly, as there
is no error passed to OnRequestDone and THttpCli.DoRequestSync()
doesn't raise an exception which it should IMO.  

So what about a new HTTP error code "httperrNoStatusCode"
and a change in the following code:

{code} 
procedure THttpCli.SocketSessionClosed(Sender: TObject; ErrCode: Word);
[..]
{$IFNDEF DO_NOT_USE_COREY_FIX}
    if FLocationFlag then
        LocationSessionClosed(Self, 0)
    else begin
        TriggerSessionClosed;
        if FState <> httpReady then begin
            if (FRequestDoneError = httperrNoError) and (FStatusCode = 0) then 
<== block added
            begin
                FRequestDoneError := httperrNoStatusCode;
                FReasonPhrase     := 'HTTP no status code (connection closed 
prematurely)';
            end;
            SetReady;
        end;

    end;
{$ELSE}
[..]
{code}

{code}
procedure THttpCli.DoRequestSync(Rq : THttpRequest);
[..]
{* Jul 12, 2004
   WARNING: The component now doesn't consider 401 status
            as a fatal error (no exception is triggered). This required a
            change in the application code if it was using the exception that
            is no more triggered for status 401 and 407.
*}
    {* if FStatusCode > 401 then    Dec 14, 2004 *}
    if (FRequestDoneError <> 0) or (  <== added
       (FStatusCode >= 400) and (FStatusCode <> 401) and (FStatusCode <> 407)) 
then
    begin
        if FRequestDoneError <> 0 then <== added
            raise EHttpException.Create(FReasonPhrase, FRequestDoneError) <== 
added
        else 
            raise EHttpException.Create(FReasonPhrase, FStatusCode);
    end;
{code}

See also my previous message with subject "Re: [twsocket] Delphi HTTPCli 
question".
By setting FRequestDoneError as the ErrorCode property of the exception
one would be able to handle errors much better in sync mode.
What do you/all think?

-- 
Arno Garrels

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to