Diff

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
parent 5354:18ebc3874364
child 5458:84162b81c863
line wrap: on
line diff
--- 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