net.http: Throw error when connecting to a http:// URL without LuaSec available
authorMatthew Wild <mwild1@gmail.com>
Mon, 8 Apr 2013 15:40:27 +0000 (16:40 +0100)
committerMatthew Wild <mwild1@gmail.com>
Mon, 8 Apr 2013 15:40:27 +0000 (16:40 +0100)
net/http.lua

index a1e4e52308200b7c05d4e97fe6476c93805305ff..ec55af926910dcf5a87c2ae649794e7727cb09ed 100644 (file)
@@ -11,6 +11,8 @@ local b64 = require "util.encodings".base64.encode;
 local url = require "socket.url"
 local httpstream_new = require "util.httpstream".new;
 
+local ssl_available = pcall(require, "ssl");
+
 local server = require "net.server"
 
 local t_insert, t_concat = table.insert, table.concat;
@@ -177,6 +179,9 @@ function request(u, ex, callback)
        req.method, req.headers, req.body = method, headers, body;
        
        local using_https = req.scheme == "https";
+       if using_https and not ssl_available then
+               error("SSL not available, unable to contact https URL");
+       end
        local port = tonumber(req.port) or (using_https and 443 or 80);
        
        -- Connect the socket, and wrap it with net.server