#1 2019-05-05 20:08:45

Eugene Ilyin
Member
From: milky_way/orion_arm/sun/earth
Registered: 2016-03-27
Posts: 132
Website

Extend THttpServerRequest.Prepare in SynCrtSock when HTTPS is used

Hi,
Please add a minor change which is fully compatible with the current usage of THttpServerRequest class into SynCrtSock.pas

Motivation
In order to use incoming HTTP Request objects with different HTTP server methods we need an API to build request with the same data and necessary changes. We can clone/copy all request fields for HTTP traffic. But this is impossible for HTTPS traffic due to hardcoded fUseSSL := False; in THttpServerRequest.Prepare method.

Current version:

  THttpServerRequest = class
  ...
    procedure Prepare(const aURL,aMethod,aInHeaders,aInContent,aInContentType,
      aRemoteIP: SockString);

...

procedure THttpServerRequest.Prepare(const aURL, aMethod,
  aInHeaders, aInContent, aInContentType, aRemoteIP: SockString);
begin
  ...
  fUseSSL := False;
end;

Suggested version:

  THttpServerRequest = class
  ...
    procedure Prepare(const aURL,aMethod,aInHeaders,aInContent,aInContentType,
      aRemoteIP: SockString; const aUseSSL: Boolean = False);

...

procedure THttpServerRequest.Prepare(const aURL, aMethod,
  aInHeaders, aInContent, aInContentType, aRemoteIP: SockString; const aUseSSL: Boolean);
begin
  ...
  fUseSSL := aUseSSL;
end;

I'm always add this const aUseSSL: Boolean = False to support transformations in HTTPS requests, but patching the framework on each used night-build release is boring/error prone neutral

Better way: you can add aUseSSL without default parameter value and update the code, which is use Prepare method (couple of places). I think that we can ignore that this is not a backward compatible variant, I'm not sure that someone call Prepare directly in their projects. I'm using it intensively in mORMotBP project of course, due to lot of required transformations on incoming HTTP Request data and drop all SSL traffic support is not an option. Also this variant makes the useSSL field is more consistent with other request parameters.

Last edited by Eugene Ilyin (2019-05-05 20:19:47)

Offline

#2 2019-05-05 20:46:37

Eugene Ilyin
Member
From: milky_way/orion_arm/sun/earth
Registered: 2016-03-27
Posts: 132
Website

Re: Extend THttpServerRequest.Prepare in SynCrtSock when HTTPS is used

@ab, can you extend this method signature, please?
There are not so many usages of it:

SynCrtSock:6227       
  ctxt.Prepare(URL,Method,HeaderGetText(fRemoteIP),Content,ContentType,'');

SynBidirSock:1686     
  Ctxt.Prepare(URL,Method,InHeaders,InContent,InContentType,fRemoteIP);

SynBidirSock:3131     
  Ctxt.Prepare(url,method,header,data,dataType,'');

mORMotHttpServer:1157 
  ctxt.Prepare(FormatUTF8('%/%/%',[aSender.Model.Root, aInterfaceDotMethodName,aFakeCallID]),'POST','','['+aParams+']','','');

Last edited by Eugene Ilyin (2019-05-06 19:48:55)

Offline

#3 2019-05-08 19:55:27

Eugene Ilyin
Member
From: milky_way/orion_arm/sun/earth
Registered: 2016-03-27
Posts: 132
Website

Re: Extend THttpServerRequest.Prepare in SynCrtSock when HTTPS is used

Hi @ab, do you see any issues with this minor update?

Offline

#4 2019-05-09 07:53:08

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

Re: Extend THttpServerRequest.Prepare in SynCrtSock when HTTPS is used

Please check https://synopse.info/fossil/info/b6242953ba

Sorry for the delay.
smile

Offline

#5 2019-05-12 18:01:30

Eugene Ilyin
Member
From: milky_way/orion_arm/sun/earth
Registered: 2016-03-27
Posts: 132
Website

Re: Extend THttpServerRequest.Prepare in SynCrtSock when HTTPS is used

@ab, many thanks!

Offline

Board footer

Powered by FluxBB