#1 2022-08-19 07:42:49

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

websocket client does not get reponse if slashes exist

I have copied an existing working skeleton of a websocket client/server example I have made for my work
The copied project had one major problem:
Websocket client connects, it does everything ) need as rest client, it does not disconnect but it never gets a websocket response through the callback interface (more or less the same with the existing sample in Mormot1)
After spending a couple of hours to find what happens, I found the problem:
The orm model (used by trestserver and TRestHttpClientWebsockets) is created with a url base that contains a slash like 'base1/subbase2'
if this slash is missing, everything is ok
Is it my fault, or is it a bug?

To describe it better, I wanted to have one base 'urlbase' and two different Trestservers after that, one with authentication ('/urlbase/main') and the other without ('/urlbase/auth').
Is it possible to have a base url for the TRestHttpServer and each Trestrerver after this base url?

Last edited by dcoun (2022-08-19 08:10:04)

Offline

#2 2022-08-19 10:24:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: websocket client does not get reponse if slashes exist

I don't see where the '/' is not supported.
Do you have any hint?

There is no such thing as a "base URI" yet.

Offline

#3 2022-08-20 14:05:55

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: websocket client does not get reponse if slashes exist

ab wrote:

I don't see where the '/' is not supported.
Do you have any hint?

The same project with websocket server and client works OK if no slash exists in the URI in model's creation.
if a slash exists, REST works ok, but the client never receives the websocket responses from the server

Offline

#4 2022-08-20 14:48:27

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: websocket client does not get reponse if slashes exist

Trying examples from mormot2/ex/rest-websockets
Running restws_longworkserver and restws_longworkclient as it is in repository
Received the following in the client

Service.TotalWorkCount=1
>20220820 14403901  " trace mormot.net.ws.client.TWebSocketProcessClient(053b4458) GetFrame  frames focBinary len=102
20220820 14403901  " trace mormot.net.ws.client.TWebSocketProcessClient(053b4458) GetSubFrame(1/2)  r000001 focBinary len=63
Received callback WorkFinished(help) in 5047ms
>20220820 14403901  " trace mormot.net.ws.client.TWebSocketProcessClient(053b4458) GetSubFrame(2/2)  r000002 focBinary len=29

Now in line 106,in the server

  Server := TRestServerFullMemory.CreateWithOwnModel([],False,'root/test');

and in line 98 in the client

        Client := TRestHttpClientWebsockets.Create('127.0.0.1', '8888', TOrmModel.Create([],'root/test'),false,'','',0,0,2000);

Running them and the response in the client it is now:

Service.TotalWorkCount=1
>20220820 14424803  " trace mormot.net.ws.client.TWebSocketProcessClient(04944458) GetFrame  frames focBinary len=131
20220820 14424803  " trace mormot.net.ws.client.TWebSocketProcessClient(04944458) GetSubFrame(1/2)  r000001 focBinary len=87
20220820 14424803  " trace mormot.net.ws.client.TWebSocketProcessClient(04944458) GetSubFrame(2/2)  r000002 focBinary len=34

both compiled with delphi 11.1

Offline

#5 2022-08-20 16:47:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: websocket client does not get reponse if slashes exist

So it works?

I don't get your point.

Offline

#6 2022-08-20 17:08:47

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: websocket client does not get reponse if slashes exist

ab wrote:

So it works?

No. It does NOT work

As shown above procedure TLongWorkCallback.WorkFinished never get called

Offline

#7 2022-08-21 07:01:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: websocket client does not get reponse if slashes exist

Did you debug a little more to find out why and propose a pull request to fix it?

Offline

#8 2022-08-21 08:40:24

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: websocket client does not get reponse if slashes exist

ab wrote:

Did you debug a little more to find out why and propose a pull request to fix it?

The problem is in mormot.rest.client, line 2347

The following works for me, but I am sure what you believe it is the best approach

  i:=Length(fModel.Root);
  root:=Copy(url,1,i);
  Split(Copy(url,i+2,4096), '/', interfmethod, id);

url ,root variable are not needed any more (a delete could be more efficient) but do you need them for cleaner code?

Last edited by dcoun (2022-08-21 09:04:17)

Offline

#9 2022-08-21 13:39:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: websocket client does not get reponse if slashes exist

Offline

#10 2022-08-21 13:59:26

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: websocket client does not get reponse if slashes exist

Thanks a lot @ab

Offline

Board footer

Powered by FluxBB