WebObjects/Web Applications/Development/SSL

Detecting SSL edit

Code for detecting whether SSL is active for the current request: I'm told this won't work with IIS:

 // Is this page being accessed securely?
 boolean secureMode = false;
 String header = context.request().headerForKey("https");
 if( header == null ) {
   log.debug( "no https header, looking for server_port" );
   header = context.request().headerForKey( "server_port" );
   if( header == null ) {
     log.debug( "no server_port header found, assuming insecure connection" );
   } else {
     log.debug( "server_port header found, using it" );
     secureMode = header.equals( "443" );
   }
 } else {
   log.debug( "https header found, using it" );
   secureMode = header.equals( "on" );
 }
 log.debug( "secure mode set to " + secureMode );