mod_http: Fix traceback when no HTTP services succeed in binding
[prosody.git] / plugins / mod_bosh.lua
index 3b5e3e1edfc0bf5942c82219741e2bde948bf428..8b612286f7c0b7116be3ef830686f0c535acaf41 100644 (file)
@@ -98,13 +98,6 @@ function on_destroy_request(request)
        end
 end
 
-local function handle_GET(request)
-       return [[<html><body>
-       <p>It works! Now point your BOSH client to this URL to connect to Prosody.</p>
-       <p>For more information see <a href="http://prosody.im/doc/setting_up_bosh">Prosody: Setting up BOSH</a>.</p>
-</body></html>]];
-end
-
 function handle_OPTIONS(request)
        local headers = {};
        for k,v in pairs(default_headers) do headers[k] = v; end
@@ -262,7 +255,7 @@ function stream_callbacks.streamopened(context, attr)
                
                session.log("debug", "BOSH session created for request from %s", session.ip);
                log("info", "New BOSH session, assigned it sid '%s'", sid);
-               local r, send_buffer = session.requests, session.send_buffer;
+               local r = session.requests;
                function session.send(s)
                        -- We need to ensure that outgoing stanzas have the jabber:client xmlns
                        if s.attr and not s.attr.xmlns then
@@ -379,7 +372,7 @@ function stream_callbacks.error(context, error)
                local response = context.response;
                response.headers = default_headers;
                response.status_code = 400;
-               request:send();
+               response:send();
                return;
        end
        
@@ -428,13 +421,24 @@ function on_timer()
 end
 module:add_timer(1, on_timer);
 
+
+local GET_response = {
+       headers = {
+               content_type = "text/html";
+       };
+       body = [[<html><body>
+       <p>It works! Now point your BOSH client to this URL to connect to Prosody.</p>
+       <p>For more information see <a href="http://prosody.im/doc/setting_up_bosh">Prosody: Setting up BOSH</a>.</p>
+       </body></html>]];
+};
+
 function module.add_host(module)
        module:depends("http");
        module:provides("http", {
                default_path = "/http-bind";
                route = {
-                       ["GET"] = handle_GET;
-                       ["GET /"] = handle_GET;
+                       ["GET"] = GET_response;
+                       ["GET /"] = GET_response;
                        ["OPTIONS"] = handle_OPTIONS;
                        ["OPTIONS /"] = handle_OPTIONS;
                        ["POST"] = handle_POST;