Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
1330:baad431dabc5 | 1331:4443309b5528 |
---|---|
7 | 7 |
8 local connlisteners_get = require "net.connlisteners".get; | 8 local connlisteners_get = require "net.connlisteners".get; |
9 local listener = connlisteners_get("httpclient") or error("No httpclient listener!"); | 9 local listener = connlisteners_get("httpclient") or error("No httpclient listener!"); |
10 | 10 |
11 local t_insert, t_concat = table.insert, table.concat; | 11 local t_insert, t_concat = table.insert, table.concat; |
12 local tonumber, tostring, pairs, xpcall, select, debug_traceback, char = | 12 local tonumber, tostring, pairs, xpcall, select, debug_traceback, char, format = |
13 tonumber, tostring, pairs, xpcall, select, debug.traceback, string.char; | 13 tonumber, tostring, pairs, xpcall, select, debug.traceback, string.char, string.format; |
14 | 14 |
15 local log = require "util.logger".init("http"); | 15 local log = require "util.logger".init("http"); |
16 local print = function () end | 16 local print = function () end |
17 | 17 |
18 local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end | |
19 | |
20 module "http" | 18 module "http" |
19 | |
20 function urlencode(s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end | |
21 function urldecode(s) return s and (s:gsub("%%(%x%x)", function (c) return char(tonumber(c,16)); end)); end | |
21 | 22 |
22 local function expectbody(reqt, code) | 23 local function expectbody(reqt, code) |
23 if reqt.method == "HEAD" then return nil end | 24 if reqt.method == "HEAD" then return nil end |
24 if code == 204 or code == 304 then return nil end | 25 if code == 204 or code == 304 then return nil end |
25 if code >= 100 and code < 200 then return nil end | 26 if code >= 100 and code < 200 then return nil end |