Comparison

mod_websocket/mod_websocket.lua @ 689:4d21bd5dde49

mod_websocket: Be nice to non-websocket clients
author Florian Zeitz <florob@babelmonkeys.de>
date Sun, 27 May 2012 17:53:52 +0200
parent 688:e87678a52720
child 690:5acc203972f3
comparison
equal deleted inserted replaced
688:e87678a52720 689:4d21bd5dde49
313 end 313 end
314 314
315 function handle_request(event, path) 315 function handle_request(event, path)
316 local request, response = event.request, event.response; 316 local request, response = event.request, event.response;
317 317
318 -- Add sanity checks 318 if not request.headers.sec_websocket_key then
319 response.headers.content_type = "text/html";
320 return [[<!DOCTYPE html><html><head><title>Websocket</title></head><body>
321 <p>It works! Now point your WebSocket client to this URL to connect to Prosody.</p>
322 </body></html>]];
323 end
319 324
320 response.conn:setlistener(listener); 325 response.conn:setlistener(listener);
321 response.status = "101 Switching Protocols"; 326 response.status = "101 Switching Protocols";
322 response.headers.Upgrade = "websocket"; 327 response.headers.Upgrade = "websocket";
323 response.headers.Connection = "Upgrade"; 328 response.headers.Connection = "Upgrade";