Diff

net/http.lua @ 1331:4443309b5528

net.http: (Re-)add url[en|de]code functions
author Matthew Wild <mwild1@gmail.com>
date Fri, 12 Jun 2009 11:21:11 +0100
parent 1112:e8a00a2ea910
child 1522:569d58d21612
line wrap: on
line diff
--- a/net/http.lua	Mon Jun 08 13:25:10 2009 +0100
+++ b/net/http.lua	Fri Jun 12 11:21:11 2009 +0100
@@ -9,15 +9,16 @@
 local listener = connlisteners_get("httpclient") or error("No httpclient listener!");
 
 local t_insert, t_concat = table.insert, table.concat;
-local tonumber, tostring, pairs, xpcall, select, debug_traceback, char = 
-        tonumber, tostring, pairs, xpcall, select, debug.traceback, string.char;
+local tonumber, tostring, pairs, xpcall, select, debug_traceback, char, format = 
+        tonumber, tostring, pairs, xpcall, select, debug.traceback, string.char, string.format;
 
 local log = require "util.logger".init("http");
 local print = function () end
 
-local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end
+module "http"
 
-module "http"
+function urlencode(s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end
+function urldecode(s) return s and (s:gsub("%%(%x%x)", function (c) return char(tonumber(c,16)); end)); end
 
 local function expectbody(reqt, code)
     if reqt.method == "HEAD" then return nil end