WebObjects/Web Applications/Development/SSL
Appearance
Detecting SSL
[edit | edit source]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 );