#1 2015-10-30 18:16:21

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

How can I send a custom http header through TSQLHttpClient?

I'm using only the http layer of mormot (Interface based services) in a legacy (ex-datasnap) project. I'm developing my own authentication methods (because of compatibility issues) and I want to send a session token from the client to the server in every request. I guess I can do that with a custom header.

Which is the right way to do this?

I didn't find any Headers property. I tried to override some internal methods of TSQLHttpClient but without success. I guess I'm looking in the wrong place.

Last edited by Roberto Schneiders (2015-10-30 18:18:07)

Offline

#2 2015-11-03 19:18:16

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

Re: How can I send a custom http header through TSQLHttpClient?

I could use a modified version of TSQLRestServerAuthenticationHttpBasic, overriding the CheckPassword method, but I have one problem. AFAIK, mORMot save the authentication details (token/signature) in memory, and this would not work for me.

I will have more then one server running (Using AWS Auto-scaling/Load Balancer), so, I need to persist that data on Redis.

Any ideas how to do that?

Offline

#3 2015-11-04 09:39:08

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

Re: How can I send a custom http header through TSQLHttpClient?

In fact, headers are something tied to HTTP.

Whereas you may call interfaces outside the HTTP/REST layer.

IMHO the easiest is to use a sicClientDriven kind of interface-based service.
The "session" authentication would stay as long as the client would have its instance running.

Offline

#4 2015-11-04 11:19:05

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

Re: How can I send a custom http header through TSQLHttpClient?

The major problem is that the load balancer (AWS ELB) will send the request to any of the servers and it is not predictable. So, I can't rely on any in-memory information/session on the server side.

This server will serve a ton of clients with a low usage per client, so, I'm using sicPerThread.

Offline

#5 2015-11-04 12:37:33

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

Re: How can I send a custom http header through TSQLHttpClient?

Pass the session ID as parameter, or try to make the services stateless...

From my point of view I would use a mORMot server as load balancing front end, perhaps...

Offline

#6 2015-11-04 13:38:47

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

Re: How can I send a custom http header through TSQLHttpClient?

I have some methods that are called in the DBX layer, some sort of a IAPPServer crazy wrapper, so, it will be much easier to send the session id on a HTTP Header rather than a explicit parameter.

In fact, It is perfectly possible to make a full stateless server, but, I will have to send some information from the client (like the user id) in every request, which is fine if I can send via Header or something like that, but, if I have to send those params explicitly in every method, it will became a mess.

About the Load Balancer, use mORMot can be a good idea, but, It will bring me some new problems. The ELB automatically adjust itself according to the traffic, if I use mORMot I will have to use a fixed EC2 machine that can support our peak usage (primarily network bandwidth), which can became expensive. ELB also gives me a free failover system. If one of the servers became offline, it will automatically launch a new server. I think this will be a lot more complicated to do without ELB.

Offline

#7 2015-11-04 16:29:21

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

Re: How can I send a custom http header through TSQLHttpClient?

Just an idea, in SynCrtSock.pas THTTPRequest has several methods where a custom header could be send:

class function Get(const aURI: SockString; const aHeader: SockString=''; aIgnoreSSLCertificateErrors: Boolean=true): SockString;
class function Post(const aURI, aData: SockString; const aHeader: SockString=''; aIgnoreSSLCertificateErrors: Boolean=true): SockString;
...
function Request(const url, method: SockString; KeepAlive: cardinal; const InHeader, InData, InDataType: SockString; out OutHeader, OutData: SockString): integer; virtual;

I mean you could use Interfaced based services on servicer side and a TWinHTTPClient on client side to call the services with your custom headers.

Last edited by danielkuettner (2015-11-04 16:36:52)

Offline

#8 2015-11-04 17:42:42

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

Re: How can I send a custom http header through TSQLHttpClient?

Thanks Daniel,

I was able to change the headers by overriding the InternalRequest on TSQLHttpClient.

function InternalRequest(const url, method: RawUTF8; var Header, Data, DataType: RawUTF8): Int64Rec; override;

Offline

Board footer

Powered by FluxBB