开发者

How can my Apache 2 module tell if it is being called via an SSL request?

开发者 https://www.devze.com 2023-01-14 20:28 出处:网络
I have a module that needs to return a reference URI in its payload. If called via an SSL connection, I need to build a URI that has the https prefix. I can easily get the port number from the request

I have a module that needs to return a reference URI in its payload. If called via an SSL connection, I need to build a URI that has the https prefix. I can easily get the port number from the request, but the problem is the user could have picked any port for SSL (and in fact this particular Apache instance always starts out with a non-standard SSL port).

All of the parsed URI's in the request structure already have the http/https prefix removed. I'm contemplating resorting to the r->server->defn_name field, which actually has the conf file for the request's virtual server in it. If I see that ends with httpd-ssl.conf, I can guess this is an SSL connection. Still feels like a hack, and in reality the user could name that conf file something else too, which would break this approach.

Another approach would be to read the config file and find the SSL VirtualHost Listen port, but I haven't been able to accomplish t开发者_运维技巧his either.

It seems like I am missing some very simple way to tell if the request was made via https, but I have scanned all of the structures available from the request_rec and I don't see anything obvious.


There is a nice function defined in the httpd.h header file that will give you the scheme for a request:

if (apr_strnatcmp(ap_http_scheme(r), "https") == 0) {
    ssl = TRUE;    
} else {
    ssl = FALSE;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消