Distinguish HTTP from HTTPS in Force.com Sites

I’m developing on Force.com Sites, and having trouble distinguishing whether the current request is coming in on HTTP or HTTPS. Do you have any tips?

ApexPages.CurrentPage().getUrl();
// ==> relative url without the domain or protocol

ApexPages.CurrentPage().getHeaders() 
// doesn't dependably include any url information

Answer

You could use the URL class:

System.debug('URL Protocol: ' + URL.getSalesforceBaseUrl().getProtocol()); 

Attribution
Source : Link , Question Author : Benj , Answer Author : Daniel Ballinger

Leave a Comment