Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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
share|improve this question
    
Once you know whether it is HTTP or HTTPS, what do you plan to do? ;-) –  user320 Mar 26 at 17:05
    
Use a <page action={!actionFunction} to force the HTTP request to reload in HTTPS for a few particularly sensitive pages. –  Benj Mar 26 at 21:05
add comment

2 Answers 2

up vote 6 down vote accepted

You could use the URL class:

System.debug('URL Protocol: ' + URL.getSalesforceBaseUrl().getProtocol()); 
share|improve this answer
add comment
Site.getCurrentSiteUrl()
// Returns: https://sites-labs-demo-developer-edition.na9.force.com/test
share|improve this answer
1  
This would totally work, but I ended up going with Daniel's approach and its handy getProtocol shortcut –  Benj Mar 26 at 21:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.