Skip to content

Commit 58c2d28

Browse files
committed
http/hsts: Use http.util.is_ip function
1 parent e3ed1a0 commit 58c2d28

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

http/hsts.lua

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ Data structures useful for HSTS (HTTP Strict Transport Security)
33
HSTS is described in RFC 6797
44
]]
55

6-
local EOF = require "lpeg".P(-1)
7-
local IPv4address = require "lpeg_patterns.IPv4".IPv4address
8-
local IPv6address = require "lpeg_patterns.IPv6".IPv6address
9-
local IPaddress = (IPv4address + IPv6address) * EOF
6+
local http_util = require "http.util"
107

118
local store_methods = {
129
time = function() return os.time() end;
@@ -23,14 +20,6 @@ local store_item_mt = {
2320
__index = store_item_methods;
2421
}
2522

26-
local function host_is_ip(host)
27-
if IPaddress:match(host) then
28-
return true
29-
else
30-
return false
31-
end
32-
end
33-
3423
local function new_store()
3524
return setmetatable({
3625
domains = {};
@@ -56,7 +45,7 @@ function store_methods:store(host, directives)
5645
else
5746
max_age = tonumber(max_age, 10)
5847
end
59-
if host_is_ip(host) then
48+
if http_util.is_ip(host) then
6049
return false
6150
end
6251
if max_age == 0 then
@@ -73,7 +62,7 @@ function store_methods:store(host, directives)
7362
end
7463

7564
function store_methods:check(host)
76-
if host_is_ip(host) then
65+
if http_util.is_ip(host) then
7766
return false
7867
end
7968
local now = self.time()

0 commit comments

Comments
 (0)