moonbridge

changeset 179:77d8fdd124e6

Throw error if key is not a string when accessing headers table
author jbe
date Thu Jun 18 22:38:53 2015 +0200 (2015-06-18)
parents f6eea95879d4
children 31820816f554
files moonbridge_http.lua
line diff
     1.1 --- a/moonbridge_http.lua	Thu Jun 18 22:35:52 2015 +0200
     1.2 +++ b/moonbridge_http.lua	Thu Jun 18 22:38:53 2015 +0200
     1.3 @@ -246,16 +246,17 @@
     1.4          -- (raw access, but case-insensitive):
     1.5          headers = setmetatable({}, {
     1.6            __index = function(self, key)
     1.7 -            if type(key) == "string" then
     1.8 -              local lowerkey = string.lower(key)
     1.9 -              local result = rawget(self, lowerkey)
    1.10 -              if result == nil then
    1.11 -                result = {}
    1.12 -                rawset(self, lowerkey, result)
    1.13 -              end
    1.14 -              rawset(self, key, result)
    1.15 -              return result
    1.16 +            if type(key) ~= "string" then
    1.17 +              error("Attempted to index headers table with a non-string key")
    1.18              end
    1.19 +            local lowerkey = string.lower(key)
    1.20 +            local result = rawget(self, lowerkey)
    1.21 +            if result == nil then
    1.22 +              result = {}
    1.23 +              rawset(self, lowerkey, result)
    1.24 +            end
    1.25 +            rawset(self, key, result)
    1.26 +            return result
    1.27            end
    1.28          }),
    1.29          -- table mapping header field names to value-lists

Impressum / About Us