net.http: Throw error when connecting to a http:// URL without LuaSec available
authorMatthew Wild <mwild1@gmail.com>
Mon, 08 Apr 2013 16:40:27 +0100
changeset 5448 cbe9fa2d3787
parent 5447 92b88476873a
child 5449 35a271b4b920
net.http: Throw error when connecting to a http:// URL without LuaSec available
net/http.lua
--- a/net/http.lua	Mon Apr 08 15:53:18 2013 +0100
+++ b/net/http.lua	Mon Apr 08 16:40:27 2013 +0100
@@ -11,6 +11,8 @@
 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 @@
 	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