Permalink
Browse files

Added SSL support

  • Loading branch information...
1 parent eca9cb8 commit 061f4c6ad0107d3b22bc7594d6b8ea69c27613f6 @omarkj omarkj committed May 30, 2011
View
@@ -0,0 +1,29 @@
+<!doctype html>
+<html>
+ <head>
+ <meta HTTP-equiv="X-UA-Compatible" content="IE=EDGE">
+
+ <script src="/socket.io/socket.io.js">
+ </script>
+
+ <script type="text/javascript">
+ function init() {
+ socket = new io.Socket(location.hostname, {secure: true});
+ socket.on('message', function(data){
+ console.log(data);
+ });
+ socket.on('connect', function(){
+ console.log("Imma connectad!");
+ console.log(socket);
+ socket.send({msg: "Erlang rulez!"});
+
+ });
+ socket.connect();
+ }
+ </script>
+ </head>
+
+ <body onLoad="init()">
+
+ </body>
+</html>
View
@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDhzCCAvCgAwIBAgIJAPFFl046vv7vMA0GCSqGSIb3DQEBBQUAMIGKMQswCQYD
+VQQGEwJJVDENMAsGA1UECBMEQ29tbzENMAsGA1UEBxMEQ29tbzERMA8GA1UEChMI
+TWlzdWx0aW4xETAPBgNVBAsTCE1pc3VsdGluMREwDwYDVQQDEwhNaXN1bHRpbjEk
+MCIGCSqGSIb3DQEJARYVcm9iZXJ0b0Bvc3RpbmVsbGkubmV0MB4XDTEwMDQyMDE3
+NDczOFoXDTIwMDQxNzE3NDczOFowgYoxCzAJBgNVBAYTAklUMQ0wCwYDVQQIEwRD
+b21vMQ0wCwYDVQQHEwRDb21vMREwDwYDVQQKEwhNaXN1bHRpbjERMA8GA1UECxMI
+TWlzdWx0aW4xETAPBgNVBAMTCE1pc3VsdGluMSQwIgYJKoZIhvcNAQkBFhVyb2Jl
+cnRvQG9zdGluZWxsaS5uZXQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAM8A
+BT4OzNCcgrfVnzmEp8VdyR+O0ubsSBunX8J/BTKbWgZVrrGrY9fO8AkVmD1VFm8n
+w/yLlz/Ow24j40UCY82Y9gMDgADa3B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+OgrY9PgsAcfozXgCOJP6NEP8IHzvb7kWoTussgBCd8P2Vv+YTp8WkBQDtpAlQExf
+03sKUE9+pDXnzLnq4Pore6xBlzcZ4hu35WUo854UApRT/OQB5+Kmth9pqax43bbp
+9Lfg6Zg9NXDuGHbRdK3U48uXLa7lDi5TMJ3LHuJ+DxZq4WNCTbMA3YZTFnjGiD/N
+NvTy54oQThjn67N7BQe3PeWI2ryGEWJAXShnc0ZTaxQaQn+18zVAe2tQOFUPhbbA
+Bq7zx49gea1tlJC1DHLktmw72v0g5W3HZ2fP1m+9socH9n4iORGEpicwuMgf9Tlb
+T0mFP3hL0y1wEdBoohF6Euk1Y33P44tbXsYn6bP2/mVmWphVA3wWOocMYw/UgSxM
+pzpC+z6y19dhqYNJyywgsMv6GQdrovW1DF2udmjx1Mv7qbwdJlH0GyLdyBL8aZFb
+WBXI2PjWWtZS/F1U7QsELzV3mM1U8n+K5hZuBPtvLzohpq2W59tPkg==
+-----END RSA PRIVATE KEY-----
View
@@ -3,7 +3,7 @@
-behaviour(gen_server).
%% API
--export([start_link/5]).
+-export([start_link/6]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@@ -32,10 +32,10 @@
%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
%% @end
%%--------------------------------------------------------------------
-start_link(ServerModule, Port, Resource, {DefaultHttpHandler, Args}, Sup) ->
- gen_server:start_link(?MODULE, [ServerModule, Port, Resource, {DefaultHttpHandler, Args}, Sup], []);
-start_link(ServerModule, Port, Resource, DefaultHttpHandler, Sup) ->
- gen_server:start_link(?MODULE, [ServerModule, Port, Resource, DefaultHttpHandler, Sup], []).
+start_link(ServerModule, Port, Resource, SSL, {DefaultHttpHandler, Args}, Sup) ->
+ gen_server:start_link(?MODULE, [ServerModule, Port, Resource, SSL, {DefaultHttpHandler, Args}, Sup], []);
+start_link(ServerModule, Port, Resource, SSL, DefaultHttpHandler, Sup) ->
+ gen_server:start_link(?MODULE, [ServerModule, Port, Resource, SSL, DefaultHttpHandler, Sup], []).
%%%===================================================================
%%% gen_server callbacks
@@ -52,10 +52,10 @@ start_link(ServerModule, Port, Resource, DefaultHttpHandler, Sup) ->
%% {stop, Reason}
%% @end
%%--------------------------------------------------------------------
-init([ServerModule, Port, Resource, DefaultHttpHandler, Sup]) ->
+init([ServerModule, Port, Resource, SSL, DefaultHttpHandler, Sup]) ->
Self = self(),
process_flag(trap_exit, true),
- {ok, ServerPid} = apply(ServerModule, start_link, [[{port, Port}, {http_process, Self}, {resource, Resource}]]),
+ {ok, ServerPid} = apply(ServerModule, start_link, [[{port, Port}, {http_process, Self}, {resource, Resource}, {ssl, SSL}]]),
WebServerRef = erlang:monitor(process, ServerPid),
gen_server:cast(Self, acquire_event_manager),
{ok, #state{
@@ -7,12 +7,9 @@ start_link(Opts) ->
Port = proplists:get_value(port, Opts),
HttpProcess = proplists:get_value(http_process, Opts),
Resource = proplists:get_value(resource, Opts),
- misultin:start_link([{port, Port},
- {name, false},
- {loop, fun (Req) -> handle_http(HttpProcess, Req) end},
- {ws_loop, fun (Ws) -> handle_websocket(HttpProcess, Resource, Ws) end},
- {ws_autoexit, false}
- ]).
+ SSL = proplists:get_value(ssl, Opts),
+ create_options(Port, HttpProcess, Resource, SSL),
+ misultin:start_link(create_options(Port, HttpProcess, Resource, SSL)).
file(Request, Filename) ->
misultin_req:file(Filename, Request).
@@ -51,6 +48,25 @@ ensure_longpolling_request(Request) ->
misultin_req:options([{comet, true}], Request).
%% Internal functions
+create_options(Port, HttpProcess, Resource, undefined) ->
+ [{port, Port},
+ {name, false},
+ {loop, fun (Req) -> handle_http(HttpProcess, Req) end},
+ {ws_loop, fun (Ws) -> handle_websocket(HttpProcess, Resource, Ws) end},
+ {ws_autoexit, false}];
+create_options(Port, HttpProcess, Resource, SSL) ->
+ Certfile = proplists:get_value(certfile, SSL),
+ Keyfile = proplists:get_value(keyfile, SSL),
+ Password = proplists:get_value(password, SSL),
+ [{port, Port},
+ {name, false},
+ {loop, fun (Req) -> handle_http(HttpProcess, Req) end},
+ {ws_loop, fun (Ws) -> handle_websocket(HttpProcess, Resource, Ws) end},
+ {ws_autoexit, false},
+ {ssl, [{certfile, Certfile},
+ {keyfile, Keyfile},
+ {password, Password}
+ ]}].
handle_http(Server, Req) ->
Path = misultin_req:resource([urldecode], Req),
@@ -27,6 +27,7 @@ init([Options]) ->
HttpPort = proplists:get_value(http_port, Options, 80),
DefaultHttpHandler = proplists:get_value(default_http_handler, Options),
Resource = lists:reverse(string:tokens(proplists:get_value(resource, Options, "socket.io"),"/")),
+ SSL = proplists:get_value(ssl, Options),
Origins = proplists:get_value(origins,Options,[{"*", "*"}]),
{ok, { {one_for_one, 5, 10}, [
{socketio_listener_event_manager, {gen_event, start_link, []},
@@ -38,6 +39,7 @@ init([Options]) ->
{socketio_http, {socketio_http, start_link, [ServerModule,
HttpPort,
Resource,
+ SSL,
DefaultHttpHandler,
self()]},
permanent, 5000, worker, [socketio_http]},

0 comments on commit 061f4c6

Please sign in to comment.