webmcp
view framework/env/auth/openid/_curl.lua @ 28:ea2e8f3a2776
allow webmcp path to be set in cgi script
this allows another script to include the webmcp script when the cwd is not the cgi-bin. the script needs to set the WEBMCP_PATH variable.
this allows another script to include the webmcp script when the cwd is not the cgi-bin. the script needs to set the WEBMCP_PATH variable.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Sun Sep 19 01:36:08 2010 +0200 (2010-09-19) |
parents | 47ddf0f86009 |
children | 3d43a5cf17c1 |
line source
1 function auth.openid._curl(url, curl_options)
2 -- NOTE: Don't accept URLs starting with file:// or other nasty protocols
3 if not string.find(url, "^[Hh][Tt][Tt][Pp][Ss]?://") then
4 return nil
5 end
6 local options = table.new(curl_options)
7 options[#options+1] = "-i"
8 options[#options+1] = url
9 local stdout, errmsg, status = os.pfilter(nil, "curl", unpack(options))
10 if not stdout then
11 error("Error while executing curl: " .. errmsg)
12 end
13 if status ~= 0 then
14 return nil
15 end
16 local status = tonumber(string.match(stdout, "^[^ ]+ *([0-9]*)"))
17 local headers = string.match(stdout, "(\r?\n.-\r?\n)\r?\n")
18 local body = string.match(stdout, "\r?\n\r?\n(.*)")
19 return status, headers, body
20 end