webmcp
diff framework/env/auth/openid/_curl.lua @ 20:47ddf0f86009
OpenID 2.0 Relying Party support
author | jbe/bsw |
---|---|
date | Fri Apr 02 02:11:32 2010 +0200 (2010-04-02) |
parents | |
children | 3d43a5cf17c1 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/auth/openid/_curl.lua Fri Apr 02 02:11:32 2010 +0200 1.3 @@ -0,0 +1,20 @@ 1.4 +function auth.openid._curl(url, curl_options) 1.5 + -- NOTE: Don't accept URLs starting with file:// or other nasty protocols 1.6 + if not string.find(url, "^[Hh][Tt][Tt][Pp][Ss]?://") then 1.7 + return nil 1.8 + end 1.9 + local options = table.new(curl_options) 1.10 + options[#options+1] = "-i" 1.11 + options[#options+1] = url 1.12 + local stdout, errmsg, status = os.pfilter(nil, "curl", unpack(options)) 1.13 + if not stdout then 1.14 + error("Error while executing curl: " .. errmsg) 1.15 + end 1.16 + if status ~= 0 then 1.17 + return nil 1.18 + end 1.19 + local status = tonumber(string.match(stdout, "^[^ ]+ *([0-9]*)")) 1.20 + local headers = string.match(stdout, "(\r?\n.-\r?\n)\r?\n") 1.21 + local body = string.match(stdout, "\r?\n\r?\n(.*)") 1.22 + return status, headers, body 1.23 +end