Skip to content

Invalid HTTP response status on WS script crash #23

Description

@edzius

If WS scripts crashes, server responds "HTTP/1.1 500" and in consequence Chrome/Firefox interprets status as "500 OK". It is not a critical bug but it doesn't look right. It should be "500 Internal Server Error".

There may be better approach solving this bug, however here is my fix:

diff --git a/lua-modules/wsapi-1.6/src/wsapi/xavante.lua b/lua-modules/wsapi-1.6/src/wsapi/xavante.lua
index 6c0bcec..38b29f3 100644
--- a/lua-modules/wsapi-1.6/src/wsapi/xavante.lua
+++ b/lua-modules/wsapi-1.6/src/wsapi/xavante.lua
@@ -93,12 +93,14 @@ local function wsapihandler (req, res, wsapi_run, app_prefix, docroot, app_path,
     common.send_content(res, res_iter, "send_data")
   else
     if wsapi_env.STATUS == 404 then
-      res.statusline = "HTTP/1.1 404"
+      -- Format proper HTTP status response with status code and string message
+      set_status(404)
       send_headers({ ["Content-Type"] = "text/html", ["Content-Length"] = (status and #status) or 0 })
       res:send_data(status)
     else
       local content = common.error_html(status)
-      res.statusline = "HTTP/1.1 500"
+      -- Format proper HTTP status response with status code and string message
+      set_status(500)
       send_headers({ ["Content-Type"] = "text/html", ["Content-Length"] = #content})
       res:send_data(content)
     end
-- 
1.7.10.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions