local string = string
local pairs = pairs

module((...))

escape = function(s)
	s = string.gsub(s, "([&=+%c])", function (c)
		return string.format("%%%02X", string.byte(c))
      	end)
	s = string.gsub(s, " ", "+")
	return s
end

encode = function(t)
	local s = ""
	for k,v in pairs(t) do
		s = s .. "&" .. escape(k) .. "=" .. escape(v)
	end
	return string.sub(s, 2)     -- remove first `&'
end