HttpApi with TROWinHttpServer.Path set doesn't work

(Anachronox) #1


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: - it is OK

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

(EvgenyK) #2


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

is swagger info page shown for you on ?
can you specify what version of ROSDK you are using?

(Anachronox) #3

Hello Evgeny.

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

So, 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, 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.

(RemObjects) #4

Thanks, logged as bugs://81506

(RemObjects) #5

bugs://81506 got closed with status fixed.

(EvgenyK) #6

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

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

(Anachronox) #7

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);
  inherited Create;
  fOwner := aOwner;
  fContext := aContext;

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

and it works in both cases now :slight_smile:

TROWinHttpWorker.GetPathInfo remains as you suggested:

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

Thanks, Petr.

(EvgenyK) #8

thx, changed