RTC Forums

Subscription => Support => Topic started by: brian71us on September 16, 2016, 03:56:13 PM



Title: How can I add headers to the responses from a web server?
Post by: brian71us on September 16, 2016, 03:56:13 PM

I am building a web server and providing remote functions using Real Thin Client. The application will need to provide the cross origin (CORS) header to allow the browser to make requests from the server. How do I add a header to the response? I need to add the header 'Access-Control-Allow-Origin' with a value of '*'. It would be best if this could be done directly from the TRtcHttpServer itself so it would work for all remote procedure calls (TRtcFunction).


Title: Re: How can I add headers to the responses from a web server?
Post by: D.Tkalcec (RTC) on September 16, 2016, 07:58:23 PM
You can add any response header using ...

   TRtcDataServer(Sender).Response['response-header-name']:='response-header-value';

... from any RTC event triggered before the response header was sent.

For example, you could do it from the OnRequestAccepted event on the TRtcServerModule component responsible for executing your remote functions if you only want it for remote functions handled by that RtcServerModule, or from the OnRequestAccepted event on the TRtcHttpServer component if you want it for ALL requests accepted for that Server.

Best Regards,
Danijel Tkalcec