moonbridge
changeset 178:f6eea95879d4
Check if key is a string in index metamethod of headers table
author | jbe |
---|---|
date | Thu Jun 18 22:35:52 2015 +0200 (2015-06-18) |
parents | b03857995d57 |
children | 77d8fdd124e6 |
files | moonbridge_http.lua |
line diff
1.1 --- a/moonbridge_http.lua Thu Jun 18 22:27:57 2015 +0200 1.2 +++ b/moonbridge_http.lua Thu Jun 18 22:35:52 2015 +0200 1.3 @@ -246,14 +246,16 @@ 1.4 -- (raw access, but case-insensitive): 1.5 headers = setmetatable({}, { 1.6 __index = function(self, key) 1.7 - local lowerkey = string.lower(key) 1.8 - local result = rawget(self, lowerkey) 1.9 - if result == nil then 1.10 - result = {} 1.11 - self[lowerkey] = result 1.12 + if type(key) == "string" then 1.13 + local lowerkey = string.lower(key) 1.14 + local result = rawget(self, lowerkey) 1.15 + if result == nil then 1.16 + result = {} 1.17 + rawset(self, lowerkey, result) 1.18 + end 1.19 + rawset(self, key, result) 1.20 + return result 1.21 end 1.22 - self[key] = result 1.23 - return result 1.24 end 1.25 }), 1.26 -- table mapping header field names to value-lists