#1 2015-12-14 11:42:27

fabioxgn
Member
Registered: 2015-11-06
Posts: 34

Use proxy with TSQLHttpClientWebsockets

Is it possible?

I've implemented a callback method using TSQLHttpServer and Websockets but as I can tell from my tests and the code, the TSQLHttpClientWebsockets uses a TCrtSocket derived class which does not allow proxy configuration.

I tried to set the proxy in WinHTTP using

netsh winhttp import proxy source=ie

but this class is not using it.

Can I use a proxy server with the TSQLHttpClientWebsockets class?

Offline

#2 2015-12-14 12:22:10

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

Re: Use proxy with TSQLHttpClientWebsockets

You would not be able to use WebSockets on most HTTP proxies, I'm afraid.
See http://www.infoq.com/articles/Web-Sockets-Proxy-Servers
It will depend on the proxy used at corporate level.

It is not a limitation of TCrtSocket, but of the proxy itself, which does not support WebSockets.
Only less efficient, but more compatible long polling may be compatible with a proxy.

Long polling is planned, but not yet implemented.
See http://synopse.info/forum/viewtopic.php?id=3060

Offline

#3 2015-12-14 13:03:20

fabioxgn
Member
Registered: 2015-11-06
Posts: 34

Re: Use proxy with TSQLHttpClientWebsockets

ab, thanks, but in my tests the TCrtSocket is not even trying to use the proxy, it is trying to make a direct connection.

I opened a proxy server on my host and configured it on a VM, other http requests pass by the proxy server, but the TCrtSocket tries to open a direct connection, is it expected?

Offline

#4 2015-12-14 13:49:24

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

Re: Use proxy with TSQLHttpClientWebsockets

The current version of TCrtSocket does not handle a proxy connection, you are right.
Using the default HTTP client - not the WebSockets version - would use the proxy.
Any input is welcome.

Offline

#5 2015-12-14 14:33:22

fabioxgn
Member
Registered: 2015-11-06
Posts: 34

Re: Use proxy with TSQLHttpClientWebsockets

ab, so there is no way to use Websockets with proxy at this time, right?

Offline

#6 2015-12-14 15:05:48

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

Re: Use proxy with TSQLHttpClientWebsockets

No, because the proxy would very likely block the websockets stream.

Offline

#7 2015-12-14 17:34:14

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 357

Re: Use proxy with TSQLHttpClientWebsockets

I'd say it depends on the configuration and what somebody understands as a "proxy". When I use apache as a "proxy" and mORMot as it is, then Websockets works as expected.

Offline

#8 2015-12-14 18:29:59

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

Re: Use proxy with TSQLHttpClientWebsockets

I guess we are talking about a corporate HTTP proxy, filtering all HTTP requests, not a HTTP server installed as a reverse proxy.
wink

Offline

#9 2015-12-14 19:01:58

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 357

Re: Use proxy with TSQLHttpClientWebsockets

Ok, what about a Browser that talks about a (real) proxy (squid) with my mORMot (I mean over websockets)?

Offline

#10 2015-12-14 19:02:07

fabioxgn
Member
Registered: 2015-11-06
Posts: 34

Re: Use proxy with TSQLHttpClientWebsockets

Exactly, the problem is a corporate proxy not reverse proxy.

Offline

#11 2015-12-14 20:19:46

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 357

Re: Use proxy with TSQLHttpClientWebsockets

ab wrote:

It is not a limitation of TCrtSocket, but of the proxy itself, which does not support WebSockets.

Browser-->squid-->apache-->mORMot? That works for me.

@fabioxgn
If it's not limitation of TCrtSocket, than something must be wrong with the proxy (or your configuration).

Last edited by danielkuettner (2015-12-14 20:25:19)

Offline

#12 2015-12-14 21:05:16

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

Re: Use proxy with TSQLHttpClientWebsockets

@Daniel
This is the other way round.

mORMot TCrtSocket client -> corporate proxy -> mORMot Server

The corporate proxy is blocking WebSockets here.

Offline

#13 2015-12-14 21:12:49

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 357

Re: Use proxy with TSQLHttpClientWebsockets

@ab
The way is the same: Chrome->squid->mORMot

What is the corporate proxy? Is squid a corporate proxy?

Ok, now I understand: the corporate proxy, is a proxy in the company, that blocks the websockets.

I thought, it were a question of "is it possible to use websockets over a proxy?".

Last edited by danielkuettner (2015-12-14 21:22:13)

Offline

#14 2015-12-16 08:17:59

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 357

Re: Use proxy with TSQLHttpClientWebsockets

Something is confusing me here:

If I use a js client (192.168.1.249) and create a websocket with ws://192.168.16/ to my mORMot
with my "corporate" proxy (192.168.1.10) than RemoteIP in THttpServerSocket.IntiRequest is 192.168.1.10.

That means, websocket traffic and "corporate" proxy is working, or am I wrong?

But if I test with Project31ChatClient than RemoteIP in THttpServerSocket.IntiRequest is 192.168.1.249. Why is TSQLHttpClientWinSock not using the Windows system proxy settings?

I ask just to better understand the things.

Offline

#15 2015-12-16 08:35:14

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

Re: Use proxy with TSQLHttpClientWebsockets

Most "corporate" proxy at 192.168.1.10 would just reject WebSockets IP frames as invalid, since they are not HTTP frames any more...

Offline

#16 2015-12-16 08:36:30

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 357

Re: Use proxy with TSQLHttpClientWebsockets

But why it works with ajax?

Offline

#17 2015-12-16 17:14:13

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

Re: Use proxy with TSQLHttpClientWebsockets

In such situations, AJAX apps do fallback to long-polling or other similar techniques.

Offline

#18 2015-12-17 16:29:33

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 357

Re: Use proxy with TSQLHttpClientWebsockets

Sometimes the words I use are not correct, I'm sorry. With ajax I meant just a simple javascript websocket like this: ws = new WebSocket("ws://192.168.1.16:8888/", "");
I can't believe that here are long polling will be used.

Now after testing a little bit I want to share my experiences:

ws = new WebSocket("ws://192.168.1.16:8888/", "") works with SimpleEchoServer over a forward (forward is more precise than corporate) proxy.

Than I've played with/in mORMotHttpclient.pas

constructor TSQLHttpClientGeneric.Create(const aServer, aPort: AnsiString;
  aModel: TSQLModel; SendTimeout,ReceiveTimeout,ConnectTimeout: DWORD);
begin
  inherited Create(aModel);
  fServer := aServer;
  fPort := aPort;

  fServer:= '192.168.1.10';  <-- this is the proxy
  fPort:= '3128'; <-- this is the proxy port

  fKeepAliveMS := 20000; // 20 seconds connection keep alive by default
  fCompression := [hcSynLZ]; // may add hcDeflate for AJAX clients
  fConnectTimeout := ConnectTimeout;
  fSendTimeout := SendTimeout;
  fReceiveTimeout := ReceiveTimeout;
end;

and in SynCrtSock.pas

procedure TSQLHttpClientGeneric.InternalURI(var Call: TSQLRestURIParams);
var Head, Content, ContentType: RawUTF8;
    P: PUTF8Char;
    res: Int64Rec;
begin
{$ifdef WITHLOG}
  fLogClass.Enter(self,nil,true);
{$endif}
  Head := Call.InHead;

  Head:= 'Host: 192.168.1.16:8888'; <-- in case of a proxy the header must have a new line with the (real) target host

...

procedure THttpClientSocket.RequestSendHeader(const url, method: SockString);
var aURL: SockString;
begin
  if Sock<0 then
    exit;
  if SockIn=nil then // done once
    CreateSockIn; // use SockIn by default if not already initialized: 2x faster
  if TCPPrefix<>'' then
    SockSend(TCPPrefix);
  if (url='') or (url[1]<>'/') then
    aURL := '/'+url else // need valid url according to the HTTP/1.1 RFC
    aURL := url;

  aURL:= 'http://192.168.1.16:8888/' + url; <-- here the URI of the real server (not proxy) has to be as absolute URI in case of a proxy

  SockSend([method,' ',aURL,' HTTP/1.1']);
  if Port='80' then
    SockSend(['Host: ',Server]) else
    SockSend(['Host: ',Server,':',Port]);
  SockSend(['Accept: */*'#13#10'User-Agent: ',UserAgent]);
end;

With these small changes the ChatClient connects over the proxy to the ChatServer.
But the Callback doesn't work yet.
Here I'm stuck.

@ab
Neither I need this feature at the moment nor I use a delphi client for my project. I just try to better understand the behavior of http/websockets/proxy internals.

Offline

#19 2015-12-23 21:38:34

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 357

Re: Use proxy with TSQLHttpClientWebsockets

I've found an interesting post here:

https://blogs.oracle.com/PavelBucek/ent … http_proxy

If the http-client wants to use a proxy, then he has to replace the GET with a CONNECT.

Perhaps would this be working...

Offline

#20 2015-12-23 22:28:45

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

Re: Use proxy with TSQLHttpClientWebsockets

Interesting!

Offline

Board footer

Powered by FluxBB