Software / code / prosody
Comparison
plugins/mod_websocket.lua @ 10728:2764beb552cd
mod_bosh, mod_websocket: Add config options to override GET responses
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 20 Apr 2020 11:30:59 +0100 |
| parent | 10617:8941bebd64e4 |
| child | 11114:6a608ecb3471 |
comparison
equal
deleted
inserted
replaced
| 10727:fa2a89132dfb | 10728:2764beb552cd |
|---|---|
| 128 return oc:top_tag(); | 128 return oc:top_tag(); |
| 129 end | 129 end |
| 130 | 130 |
| 131 return data; | 131 return data; |
| 132 end | 132 end |
| 133 | |
| 134 local default_get_response_body = [[<!DOCTYPE html><html><head><title>Websocket</title></head><body> | |
| 135 <p>It works! Now point your WebSocket client to this URL to connect to Prosody.</p> | |
| 136 </body></html>]] | |
| 137 local websocket_get_response_body = module:get_option_string("websocket_get_response_body", default_get_response_body) | |
| 138 | |
| 133 function handle_request(event) | 139 function handle_request(event) |
| 134 local request, response = event.request, event.response; | 140 local request, response = event.request, event.response; |
| 135 local conn = response.conn; | 141 local conn = response.conn; |
| 136 | 142 |
| 137 conn.starttls = false; -- Prevent mod_tls from believing starttls can be done | 143 conn.starttls = false; -- Prevent mod_tls from believing starttls can be done |
| 138 | 144 |
| 139 if not request.headers.sec_websocket_key or request.method ~= "GET" then | 145 if not request.headers.sec_websocket_key or request.method ~= "GET" then |
| 140 response.headers.content_type = "text/html"; | 146 response.headers.content_type = "text/html"; |
| 141 return [[<!DOCTYPE html><html><head><title>Websocket</title></head><body> | 147 return websocket_get_response_body; |
| 142 <p>It works! Now point your WebSocket client to this URL to connect to Prosody.</p> | |
| 143 </body></html>]]; | |
| 144 end | 148 end |
| 145 | 149 |
| 146 local wants_xmpp = contains_token(request.headers.sec_websocket_protocol or "", "xmpp"); | 150 local wants_xmpp = contains_token(request.headers.sec_websocket_protocol or "", "xmpp"); |
| 147 | 151 |
| 148 if not wants_xmpp then | 152 if not wants_xmpp then |