this is my way:
function getRespMsgByStatus(status_code)
if statusMap["default"]==nil then
--filled by items in this link: https://gist.github.com/tmthrgd/3504859568e1dba9ee80e260f974a708
statusMap["default"] = "An error occured";statusMap["100"] = "Continue";statusMap["101"] = "Switching Protocols";statusMap["102"] = "Processing";statusMap["200"] = "OK";statusMap["201"] = "Created";statusMap["202"] = "Accepted";statusMap["203"] = "Non-Authoritative Information"
statusMap["204"] = "No Content";statusMap["205"] = "Reset Content";statusMap["206"] = "Partial Content"
statusMap["207"] = "Multi-Status";statusMap["208"] = "Already Reported";statusMap["226"] = "IM Used";
statusMap["300"] = "Multiple Choices";statusMap["301"] = "Moved Permanently";statusMap["302"] = "Found"
statusMap["303"] = "See Other";statusMap["304"] = "Not Modified";statusMap["305"] = "Use Proxy";
statusMap["306"] = "Switch Proxy";statusMap["307"] = "Temporary Redirect";statusMap["308"] = "Permanent Redirect";statusMap["400"] = "Bad Request";statusMap["401"] = "Unauthorized";statusMap["402"] = "Payment Required";statusMap["403"] = "Forbidden";statusMap["404"] = "Not Found";statusMap["405"] = "Method Not Allowed";statusMap["406"] = "Not Acceptable";statusMap["407"] = "Proxy Authentication Required";statusMap["408"] = "Request Timeout";statusMap["409"] = "Conflict";statusMap["410"] = "Gone"
statusMap["411"] = "Length Required";statusMap["412"] = "Precondition Failed";statusMap["413"] = "Request Entity Too Large";statusMap["414"] = "Request-URI Too Long";statusMap["415"] = "Unsupported Media Type";statusMap["416"] = "Requested Range Not Satisfiable";statusMap["417"] = "Expectation Failed"
statusMap["418"] = "I'm a teapot";statusMap["419"] = "Authentication Timeout";statusMap["420"] = "Enhance Your Calm";statusMap["422"] = "Unprocessable Entity";statusMap["423"] = "Locked";
statusMap["424"] = "Failed Dependency";statusMap["426"] = "Upgrade Required";
statusMap["428"] = "Precondition Required";statusMap["429"] = "Too Many Requests"
statusMap["431"] = "Request Header Fields Too Large";statusMap["440"] = "Login Timeout"
statusMap["444"] = "No Response";statusMap["449"] = "Retry With";statusMap["450"] = "Blocked by Windows Parental Controls";statusMap["451"] = "Unavailable For Legal Reasons";statusMap["494"] = "Request Header Too Large";statusMap["495"] = "Cert Error";statusMap["496"] = "No Cert";statusMap["497"] = "HTTP to HTTPS";statusMap["498"] = "Token expired/invalid";statusMap["499"] = "Client Closed Request"
statusMap["500"] = "Internal Server Error";statusMap["501"] = "Not Implemented";statusMap["502"] = "Bad Gateway";statusMap["503"] = "Service Unavailable";statusMap["504"] = "Gateway Timeout";
statusMap["505"] = "HTTP Version Not Supported";statusMap["506"] = "Variant Also Negotiates"
statusMap["507"] = "Insufficient Storage";statusMap["508"] = "Loop Detected";statusMap["509"] = "Bandwidth Limit Exceeded";statusMap["510"] = "Not Extended";statusMap["511"] = "Network Authentication Required";statusMap["598"] = "Network read timeout error";statusMap["599"] = "Network connect timeout error"
end
if statusMap[tostring(status_code)] ~= nil then
return statusMap[tostring(status_code)]
end
return statusMap["default"]
end
On Sunday, June 17, 2018 at 12:49:39 PM UTC+4:30, Hadi Abbasi wrote:
hey there...
this is nginx response status msgs:
https://gist.github.com/tmthrgd/3504859568e1dba9ee80e260f974a708
my question is simple!
in openresty I want to convert my response status code to response text msg!
of course I could create a dictionary to map status keys to their correct msgs but I want to do it on standard mode!
in other words, I want to do it by using nginx or openresty tools.
function status_code_to_msg(status_code)
return ngx.var.status_code_to_msg(status_code)
end
thanks a lot...
Best,