I need to evaluate client certificates in an apache module.
The apache server can provide them as SSL_CLIENT_CERT and SSL_SERVER_CERT environment variables.
How can I access in ThttpServerContext the environment variables?
Thank you in advance
It's no different than any other Delphi application: System.SysUtils.GetEnvironmentVariable - RAD Studio API Documentation
Sorry, the
GetEnvironmentVariable('SERVER_ADDR')
for example does not work.
Neither
GetEnvironmentVariable('%SERVER_ADDR%')
I am looking for Apache's environment variables
There is no direct way to do that afaik. You can try to use Contest.Request.Url.Host
and see if it fits your needs.
How can I access from ThttpServerContext all the info that is passed from TwebRequest to
procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var Adapter: IWebBrokerAdapter;
begin
Adapter:=TWebBrokerAdapter.CreateRequest,Response);
Srv.DispatchRequest(Adapter);
end;
Unfortunately some internal fields are not made public in those objects. We have modified the code here, so in next release you can do it this way:
WebRequest := (TWebBrokerContext(Context).Adapter as TWebBrokerAdapter).WebRequest;
Thank you a lot Wagner
Yes, it should be, with the code I provided above.
The following gives exception:
var C:TXDataOperationContext;
begin C:=TXDataOperationContext.Current;
result:=(TWebBrokerContext(C).Adapter as TWebBrokerAdapter).WebRequest.URL;
end;
Which exception? What version of TMS Sparkle are you using?
3.18 Sep21
I can read in version log:
version 3.17
Improved: Underlying Web Broken TWebContext now accessible through a public
property in the context object of the Web Broker dispatcher.
But I can not find this TwebContext property. I am working on an apache module and I just get a core dump, in an interface function with just the above code
Do you need something else to reproduce it?
Which exception do you get?
I am using it in a Apache module and I get Core dump. Core dump in Apache usually is an exception.
Getting back to my question:
Your response:
The code:
WebRequest := (TWebBrokerContext(Context).Adapter as TWebBrokerAdapter).WebRequest;
Digging into the source:
Xdata.server.module, line 197:
TXDataOperationContext = class
and
C:=TXDataOperationContext.Current
how the TXDataOperationContext can be transformed to TWebBrokerContext?
Can you please check it again?
Can I somehow access Apache's environment variables?
What you should cast to TWebBrokerContext
is an instance of THttpServerContext
, not TXDataOperationContext
. It should be something like this:
var
C: THttpServerContext;
begin
C:=TXDataOperationContext.Current.Handler.Context;
Result:=(TWebBrokerContext(C).Adapter as TWebBrokerAdapter).WebRequest.URL;
end;
sorry property Context does not exist in TXDataOperationContext.Current.Handler.
Also the following in TXDataBaseRequestHandler is strictly protected:
property HttpContext: THttpServerContext read FHttpContext;
I have just updated to last version and the property Context does not exist.
Indeed, such property was not made public yet in the released version (it will be in next one). Here is a workaround. You can for now make it public in your XData source code and recompile packages.
Just add the following line in the public
section of the TXDataBaseRequestHandler
class (unit XData.Module.Base
):
property Context: THttpServerContext read FHttpContext;
Thank you Wagner