Mercurial > prosody-hg
comparison plugins/mod_http_errors.lua @ 11404:f7704f987439
mod_http_errors: Add some comments
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 25 Feb 2021 13:12:07 +0100 |
| parents | 747e8245f180 |
| children | a8798e04b5c8 |
comparison
equal
deleted
inserted
replaced
| 11403:747e8245f180 | 11404:f7704f987439 |
|---|---|
| 67 extra = extra; | 67 extra = extra; |
| 68 }); | 68 }); |
| 69 end | 69 end |
| 70 end | 70 end |
| 71 | 71 |
| 72 -- Main error page handler | |
| 72 module:hook_object_event(server, "http-error", function (event) | 73 module:hook_object_event(server, "http-error", function (event) |
| 73 if event.response then | 74 if event.response then |
| 74 event.response.headers.content_type = "text/html; charset=utf-8"; | 75 event.response.headers.content_type = "text/html; charset=utf-8"; |
| 75 end | 76 end |
| 76 return get_page(event.code, (show_private and event.private_message) or event.message or (event.error and event.error.text)); | 77 return get_page(event.code, (show_private and event.private_message) or event.message or (event.error and event.error.text)); |
| 77 end); | 78 end); |
| 78 | 79 |
| 80 -- Way to use the template for other things so to give a consistent appearance | |
| 79 module:hook("http-message", function (event) | 81 module:hook("http-message", function (event) |
| 80 if event.response then | 82 if event.response then |
| 81 event.response.headers.content_type = "text/html; charset=utf-8"; | 83 event.response.headers.content_type = "text/html; charset=utf-8"; |
| 82 end | 84 end |
| 83 return render(html, event); | 85 return render(html, event); |
| 84 end); | 86 end); |
| 85 | 87 |
| 88 -- Something nicer shown instead of 404 at the root path, if nothing else handles this path | |
| 86 module:hook_object_event(server, "http-error", function (event) | 89 module:hook_object_event(server, "http-error", function (event) |
| 87 local request, response = event.request, event.response; | 90 local request, response = event.request, event.response; |
| 88 if request and response and request.path == "/" and response.status_code == 404 then | 91 if request and response and request.path == "/" and response.status_code == 404 then |
| 89 response.headers.content_type = "text/html; charset=utf-8"; | 92 response.headers.content_type = "text/html; charset=utf-8"; |
| 90 local message = messages["/"]; | 93 local message = messages["/"]; |
