DZ-Jay wrote:

> we should try to replicate the behaviour in HttpCli: perhaps adding a
> new machine state that instead of re-sending when 401 is detected, it
> makes sure that the body has been sent completely, and if not, it
> delays re-sending until it does.

My attempt below works with the link Maurizio provided. Don't know 
whether it works with a proxy and/or NTLM etc. (forgot everything about it)
so it's most likely buggy but might be worth testing and fixing it ;-)

--
Arno Garrels

procedure THttpCli.StateChange(NewState : THttpState);
[..]
                      if FProxyAuthBasicState < basicDone then
                          FProxyAuthBasicState := basicNone;
                    end;
                end;

=>              { We got a 401/407 while sending body data, need to delay the }
=>              { request until all is sent. }
=>              if FAllowedToSend then
=>              begin
=>                  FDelayRequest := TRUE;
=>                  if FlgClean then begin
=>                      CleanupRcvdStream; { What we are received must be 
removed }
=>                      FReceiveLen   := 0;
=>                      SaveDoc       := FDocName;
=>                      InternalClear;
=>                      FDocName      := SaveDoc;
=>                  end;
=>                  Exit;
=>              end;

                if FlgClean then begin
                    CleanupRcvdStream; { What we are received must be removed }
                    CleanupSendStream;
                    FReceiveLen       := 0;
                    SaveDoc           := FDocName;
                    InternalClear;
                    FDocName          := SaveDoc;
                end;
[..]

procedure THttpCli.SendRequest(const Method, Version: String);
[..]
        TriggerBeforeHeaderSend(Method, Headers);
        for N := 0 to Headers.Count - 1 do
            SendCommand(Headers[N]);
        TriggerRequestHeaderEnd;
        SendCommand('');
=>      if not FDelayRequest then begin
            FCtrlSocket.PutDataInSendBuffer(FReqStream.Memory, FReqStream.Size);
            FReqStream.Clear;
            FCtrlSocket.Send(nil, 0);
=>      end;
    finally
        Headers.Free;
[..]

procedure THttpCli.SocketDataSent(Sender : TObject; ErrCode : Word);
[..]
    if Len <= 0 then begin
        FAllowedToSend := FALSE;
        TriggerSendEnd;
=>      { If we have a pending request let's send it now }
=>      if FDelayRequest then begin
=>          FDelayRequest := FALSE;
=>          FCtrlSocket.PutDataInSendBuffer(FReqStream.Memory, FReqStream.Size);
=>          FReqStream.Clear;
=>          CleanupSendStream;
=>          FSentCount := 0;
=>          FCtrlSocket.Send(nil, 0);
=>          FAllowedToSend := TRUE;
=>      end;
        Exit;
    end;
[..]
-- 
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