Skip to content

Commit 91c10f6

Browse files
committed
http/hsts: Add :remove() method
1 parent 671cd7e commit 91c10f6

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

doc/modules/http.hsts.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Creates and returns a copy of a store.
1717
Add new directives to the store about the given `host`. `directives` should be a table of directives, which *must* include the key `"max-age"`.
1818

1919

20+
### `hsts_store:remove(host)` <!-- --> {#http.hsts:remove}
21+
22+
Removes the entry for `host` from the store (if it exists).
23+
24+
2025
### `hsts_store:check(host)` <!-- --> {#http.hsts:check}
2126

2227
Returns a boolean indicating if the given `host` is a known HSTS host.

http/hsts.lua

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,13 @@ function store_methods:store(host, directives)
4949
else
5050
max_age = tonumber(max_age, 10)
5151
end
52-
if http_util.is_ip(host) then
53-
return false
54-
end
52+
5553
if max_age == 0 then
56-
-- delete from store
57-
local item = self.domains[host]
58-
if item then
59-
self.expiry_heap:remove(item)
60-
self.domains[host] = nil
61-
end
54+
return self:remove(host)
6255
else
56+
if http_util.is_ip(host) then
57+
return false
58+
end
6359
-- add to store
6460
local old_item = self.domains[host]
6561
if old_item then
@@ -77,6 +73,15 @@ function store_methods:store(host, directives)
7773
return true
7874
end
7975

76+
function store_methods:remove(host)
77+
local item = self.domains[host]
78+
if item then
79+
self.expiry_heap:remove(item)
80+
self.domains[host] = nil
81+
end
82+
return true
83+
end
84+
8085
function store_methods:check(host)
8186
if http_util.is_ip(host) then
8287
return false

0 commit comments

Comments
 (0)