Mercurial > prosody-hg
comparison net/http.lua @ 5448:cbe9fa2d3787
net.http: Throw error when connecting to a http:// URL without LuaSec available
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 08 Apr 2013 16:40:27 +0100 |
| parents | 18ebc3874364 |
| children | 84162b81c863 |
comparison
equal
deleted
inserted
replaced
| 5447:92b88476873a | 5448:cbe9fa2d3787 |
|---|---|
| 8 | 8 |
| 9 local socket = require "socket" | 9 local socket = require "socket" |
| 10 local b64 = require "util.encodings".base64.encode; | 10 local b64 = require "util.encodings".base64.encode; |
| 11 local url = require "socket.url" | 11 local url = require "socket.url" |
| 12 local httpstream_new = require "util.httpstream".new; | 12 local httpstream_new = require "util.httpstream".new; |
| 13 | |
| 14 local ssl_available = pcall(require, "ssl"); | |
| 13 | 15 |
| 14 local server = require "net.server" | 16 local server = require "net.server" |
| 15 | 17 |
| 16 local t_insert, t_concat = table.insert, table.concat; | 18 local t_insert, t_concat = table.insert, table.concat; |
| 17 local pairs, ipairs = pairs, ipairs; | 19 local pairs, ipairs = pairs, ipairs; |
| 175 | 177 |
| 176 -- Attach to request object | 178 -- Attach to request object |
| 177 req.method, req.headers, req.body = method, headers, body; | 179 req.method, req.headers, req.body = method, headers, body; |
| 178 | 180 |
| 179 local using_https = req.scheme == "https"; | 181 local using_https = req.scheme == "https"; |
| 182 if using_https and not ssl_available then | |
| 183 error("SSL not available, unable to contact https URL"); | |
| 184 end | |
| 180 local port = tonumber(req.port) or (using_https and 443 or 80); | 185 local port = tonumber(req.port) or (using_https and 443 or 80); |
| 181 | 186 |
| 182 -- Connect the socket, and wrap it with net.server | 187 -- Connect the socket, and wrap it with net.server |
| 183 local conn = socket.tcp(); | 188 local conn = socket.tcp(); |
| 184 conn:settimeout(10); | 189 conn:settimeout(10); |
