X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=net%2Fhttp.lua;h=9d2f9b968f2ec3e7173176bb80af5b996cef620c;hb=68aa12bf2c6ed9f24e90e918bff5e43ac5e3007f;hp=b39cc6fbc7de5d2940e61e5da41f2472eb194c5c;hpb=5dd6384aa54a7245faa18b685dce6544f9cb66d7;p=prosody.git diff --git a/net/http.lua b/net/http.lua index b39cc6fb..9d2f9b96 100644 --- a/net/http.lua +++ b/net/http.lua @@ -1,3 +1,11 @@ +-- Prosody IM +-- Copyright (C) 2008-2009 Matthew Wild +-- Copyright (C) 2008-2009 Waqas Hussain +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + local socket = require "socket" local mime = require "mime" @@ -9,16 +17,17 @@ local connlisteners_get = require "net.connlisteners".get; 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" +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 if code == 204 or code == 304 then return nil end