跳转到正文

WebObjects/Web 应用程序/开发/SSL

摘自维基教科书,面向开放世界的开放图书

检测 SSL

[编辑 | 编辑源代码]

用于检测 SSL 是否对当前请求有效的代码:据我所知,此代码无法与 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 );
华夏公益教科书