Skip to content

Commit 6958e33

Browse files
committed
Add a function for querying whether a certificate exists
We're using this to opportunistically redirect to https in the openresty proxy like so: rewrite_by_lua_block { local has_cert = auto_ssl:has_certificate(ngx.var.host) if has_cert then local https_uri = "https://" .. ngx.var.host .. ngx.var.request_uri ngx.redirect(https_uri, 301) end }
1 parent 9d43c23 commit 6958e33

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/resty/auto-ssl.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ function _M.challenge_server(self)
9090
server(self)
9191
end
9292

93+
function _M.has_certificate(self, domain)
94+
local has_certificate = require "resty.auto-ssl.utils.has_certificate"
95+
return has_certificate(self, domain)
96+
end
97+
9398
function _M.hook_server(self)
9499
local server = require "resty.auto-ssl.servers.hook"
95100
server(self)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
return function(auto_ssl_instance, domain, shmem_only)
2+
local shmem = ngx.shared.auto_ssl:get("domain:fullchain_der:" .. domain)
3+
if shmem then
4+
return true
5+
elseif shmem_only then
6+
return false
7+
end
8+
9+
local storage = auto_ssl_instance.storage
10+
local cert = storage:get_cert(domain)
11+
if cert then
12+
return true
13+
end
14+
15+
return false
16+
end

0 commit comments

Comments
 (0)