TROBaseSuperHTTPChannel.SendWelcome does not gracefully handle errors from the server

Hello,

Inside TROBaseSuperHTTPChannel.SendWelcome, the l_responseStream.Size is tested to check we have received a proper response and if it’s not equal to the expected value, an exception is raised.
However, that exception is much too generic and does not let us know the error indicated by the server.
Indeed, if we look inside TROBaseSuperHTTPServer, we see a few methods that send error indications with only 6 bytes.
Testing for these specific conditions inside TROBaseSuperHTTPChannel.SendWelcome would allow for a more specialized exception and thus for an easier identification of the condition causing the errors being sent.

Alternatively, one could use TROBaseSuperHTTPServer.SendError that would reply with a 500 status code, but I believe this would not help either as I didn’t see any code inside TROSynapseSuperHTTPChannel.DispatchHTTPRequest that reads the status code and would pass the error content as a valid stream.

Note that this is very low priority issue as it’s quite unusual to get errors from the handling of shHello anyway.

Hi,

you can update code in uROBaseSuperHttpChannel.pas as

procedure TROBaseSuperHTTPChannel.SendWelcome;
...
// added block
    if (l_responseStream.Size = 6) then begin
      l_responseStream.Position := 0;
      t := ReadByteFromStream(l_responseStream);
      if t = ShError then begin
        t := ReadByteFromStream(l_responseStream);
        if t in [ShError_InvalidClientId, ShError_QueueFull, ShError_UnknownOption] then
          raise EROSuperHTTPChannelException.CreateFmt('Invalid response from server for connection initiation command. ErrorCode = %d', [t]);
      end;
    end;
//end block
    if (l_responseStream.Size <> (16 + 8 + 4)) then raise EROSuperHTTPChannelException.Create(err_InvalidResponseFromServerForConnectionInitiationCommand);

it should handle 6 bytes error responses.