-function handle_request(method, body, request)
- if (not body) or request.method ~= "POST" then
- if request.method == "OPTIONS" then
- local headers = {};
- for k,v in pairs(default_headers) do headers[k] = v; end
- headers["Content-Type"] = nil;
- return { headers = headers, body = "" };
- else
- return "<html><body>You really don't look like a BOSH client to me... what do you want?</body></html>";
- end
- end
- if not method then
- log("debug", "Request %s suffered error %s", tostring(request.id), body);
- return;
- end
- --log("debug", "Handling new request %s: %s\n----------", request.id, tostring(body));
- request.notopen = true;
- request.log = log;
- request.on_destroy = on_destroy_request;
+function handle_OPTIONS(request)
+ local headers = {};
+ for k,v in pairs(default_headers) do headers[k] = v; end
+ headers["Content-Type"] = nil;
+ return { headers = headers, body = "" };
+end
+
+function handle_POST(event)
+ log("debug", "Handling new request %s: %s\n----------", tostring(event.request), tostring(event.request.body));
+
+ local request, response = event.request, event.response;
+ response.on_destroy = on_destroy_request;
+ local body = request.body;
+
+ local context = { request = request, response = response, notopen = true };
+ local stream = new_xmpp_stream(context, stream_callbacks);
+ response.context = context;