Skip to content

Commit 14c812b

Browse files
committed
http/client: Give each record type it's own metatable
1 parent 24de8ed commit 14c812b

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

http/client.lua

+21-6
Original file line numberDiff line numberDiff line change
@@ -144,32 +144,47 @@ function records_mt:__len()
144144
return self.n
145145
end
146146

147+
local record_ipv4_methods = {}
148+
local record_ipv4_mt = {
149+
__name = "http.client.record.ipv4";
150+
__index = record_ipv4_methods;
151+
}
147152
function records_methods:add_v4(addr, port)
148153
local n = self.n + 1
149-
self[n] = {
154+
self[n] = setmetatable({
150155
family = cs.AF_INET;
151156
addr = addr;
152157
port = port;
153-
}
158+
}, record_ipv4_mt)
154159
self.n = n
155160
end
156161

162+
local record_ipv6_methods = {}
163+
local record_ipv6_mt = {
164+
__name = "http.client.record.ipv6";
165+
__index = record_ipv6_methods;
166+
}
157167
function records_methods:add_v6(addr, port)
158168
local n = self.n + 1
159-
self[n] = {
169+
self[n] = setmetatable({
160170
family = cs.AF_INET6;
161171
addr = addr;
162172
port = port;
163-
}
173+
}, record_ipv6_mt)
164174
self.n = n
165175
end
166176

177+
local record_unix_methods = {}
178+
local record_unix_mt = {
179+
__name = "http.client.record.unix";
180+
__index = record_unix_methods;
181+
}
167182
function records_methods:add_unix(path)
168183
local n = self.n + 1
169-
self[n] = {
184+
self[n] = setmetatable({
170185
family = cs.AF_UNIX;
171186
path = path;
172-
}
187+
}, record_unix_mt)
173188
self.n = n
174189
end
175190

0 commit comments

Comments
 (0)