HttpApi with TROWinHttpServer.Path set doesn't work

Hello.

If I use HttpApi (TROHttpApiDispatcher) bound to TROWinHttpServer, it does work only if I do not set TROWinHttpServer.Path property. In this case I’m able to see swagger service info, like this: https://127.0.0.1:8088/api - it is OK

But if I set TROWinHttpServer.Path to e.g. “MyPath”, the link to https://127.0.0.1:8088/MyPath/api is invalid - Invalid Path and EROHttpApiRequestException(err_HttpApi_IncorrectApiRequestPath) is raised in TROHttpApiDispatcher.InvokeServiceMethod, but https://127.0.0.1:8088/MyPath is showing Server InfoPage as usual.

Hi,

When you changed /api/ path with /MyPath/ in TROHttpApiDispatcher, swagger info page also is changed from https://127.0.0.1:8088/api/ to https://127.0.0.1:8088/MyPath/. this is as expected.

is swagger info page shown for you on https://127.0.0.1:8088/MyPath/ ?
can you specify what version of ROSDK you are using?

Hello Evgeny.

Well, the problem is with the combination of TROWinHttpServer.Path and TROHttpApiDispatcher.Path, not with the TROHttpApiDispatcher itself, as I stated.

So, https://127.0.0.1:8088/MyPath/ is done by TROWinHttpServer.Path, which is used to share same port with many services. And one expects that TROHttpApiDispatcher.Path should respect the server path prefix, but it doesn’t.

From my point of view, if TROWinHttpServer.Path is A and TROHttpApiDispatcher.Path is B, the final path for swagger info page should be https://127.0.0.1:8088/A/B, otherwise the TROWinHttpServer.Path functionality will be broken, since there will be conflict, if more services will share the same port.

I’m using the latest RO SDK version, but in older one it was the same.

Thank you, Petr.

Thanks, logged as bugs://81506

bugs://81506 got closed with status fixed.

pls update uROWinHttpServer.pas as

constructor TROWinHttpWorker.Create(aOwner: TROWinHttpServer;
  aContext: IROHttpServerAPIContext);
..
  if fOwner.Path <> '' then SetPathInfo(StringReplace(fContext.Request.Path, '/' + fOwner.Path,'', [rfIgnoreCase])); //added
end;

function TROWinHttpWorker.GetPathInfo: string; //body is changed
begin
  Result := fContext.Request.Path;
end;

It seems better, but now it doesn’t work if TROWinHttpServer.Path is not set.

So I tried to change TROWinHttpWorker.Create to (“if” added to your code):

constructor TROWinHttpWorker.Create(aOwner: TROWinHttpServer;
  aContext: IROHttpServerAPIContext);
begin
  inherited Create;
  fOwner := aOwner;
  fContext := aContext;

  if fOwner.Path <> '' then SetPathInfo(StringReplace(fContext.Request.Path, '/' + fOwner.Path, '', [rfIgnoreCase])); //added
end;

and it works in both cases now :slight_smile:

TROWinHttpWorker.GetPathInfo remains as you suggested:

function TROWinHttpWorker.GetPathInfo: string;
begin
  Result := fContext.Request.Path; // body changed
{
  if fOwner.Path <> '' then begin
    Result := StringReplace(fContext.Request.Path, '/' + fOwner.Path,'', [rfIgnoreCase])
  end
  else
    Result := fContext.Request.Path;
}
end;

Thanks, Petr.

thx, changed