X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=net%2Fhttp.lua;h=a1e4e52308200b7c05d4e97fe6476c93805305ff;hb=9e1ab5393dee057c8449e648673098bb53033412;hp=59f2c0804924778b58d191192610f41b7198224a;hpb=3b635da220bdbe28712f7007be430eb6e1283912;p=prosody.git diff --git a/net/http.lua b/net/http.lua index 59f2c080..a1e4e523 100644 --- a/net/http.lua +++ b/net/http.lua @@ -7,7 +7,7 @@ -- local socket = require "socket" -local mime = require "mime" +local b64 = require "util.encodings".base64.encode; local url = require "socket.url" local httpstream_new = require "util.httpstream".new; @@ -68,7 +68,7 @@ function listener.ondisconnect(conn, err) requests[conn] = nil; end -function urlencode(s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end +function urlencode(s) return s and (s:gsub("[^a-zA-Z0-9.~_-]", 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 _formencodepart(s) @@ -154,7 +154,7 @@ function request(u, ex, callback) }; if req.userinfo then - headers["Authorization"] = "Basic "..mime.b64(req.userinfo); + headers["Authorization"] = "Basic "..b64(req.userinfo); end if ex then @@ -188,7 +188,12 @@ function request(u, ex, callback) return nil, err; end - req.handler, req.conn = server.wrapclient(conn, req.host, port, listener, "*a", using_https and { mode = "client", protocol = "sslv23" }); + local sslctx = false; + if using_https then + sslctx = ex and ex.sslctx or { mode = "client", protocol = "sslv23", options = { "no_sslv2" } }; + end + + req.handler, req.conn = server.wrapclient(conn, req.host, port, listener, "*a", sslctx); req.write = function (...) return req.handler:write(...); end req.callback = function (content, code, request, response) log("debug", "Calling callback, status %s", code or "---"); return select(2, xpcall(function () return callback(content, code, request, response) end, handleerr)); end @@ -203,7 +208,6 @@ function destroy_request(request) if request.conn then request.conn = nil; request.handler:close() - listener.ondisconnect(request.handler, "closed"); end end