From b4842301a03e478b6dd9834f0ad97a597a7c476e Mon Sep 17 00:00:00 2001 From: TJ Borromeo Date: Wed, 6 May 2015 13:16:47 -0700 Subject: [PATCH 1/5] Fix improper syntax in list brackets needed for non-standard table indexing. Also added a trailing comma as its valid (and more consistent, imo). --- httpserver-header.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpserver-header.lua b/httpserver-header.lua index d848196..f6467d6 100644 --- a/httpserver-header.lua +++ b/httpserver-header.lua @@ -5,7 +5,7 @@ return function (connection, code, extension) local function getHTTPStatusString(code) - local codez = {200="OK", 400="Bad Request", 404="Not Found", 501="Not Implemented"} + local codez = {[200]="OK", [400]="Bad Request", [404]="Not Found", [501]="Not Implemented",} local myResult = codez[code] if myResult then return myResult else return "Unknown HTTP Status" end end From 219baa7b6262a7b2f59435b521abccf7d8f89f1a Mon Sep 17 00:00:00 2001 From: TJ Borromeo Date: Wed, 6 May 2015 13:36:20 -0700 Subject: [PATCH 2/5] Update httpserver-header.lua --- httpserver-header.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/httpserver-header.lua b/httpserver-header.lua index f6467d6..38b5b6a 100644 --- a/httpserver-header.lua +++ b/httpserver-header.lua @@ -7,7 +7,8 @@ return function (connection, code, extension) local function getHTTPStatusString(code) local codez = {[200]="OK", [400]="Bad Request", [404]="Not Found", [501]="Not Implemented",} local myResult = codez[code] - if myResult then return myResult else return "Unknown HTTP Status" end + -- enforce returning valid http codes all the way throughout? + if myResult then return myResult else return codez[501] end end local function getMimeType(ext) From 0c17703b464014ca655338663654cb81e5c246da Mon Sep 17 00:00:00 2001 From: TJ Borromeo Date: Wed, 6 May 2015 13:39:32 -0700 Subject: [PATCH 3/5] change return type allows the error check to be more functional --- httpserver-header.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpserver-header.lua b/httpserver-header.lua index 38b5b6a..599c3e5 100644 --- a/httpserver-header.lua +++ b/httpserver-header.lua @@ -8,7 +8,7 @@ return function (connection, code, extension) local codez = {[200]="OK", [400]="Bad Request", [404]="Not Found", [501]="Not Implemented",} local myResult = codez[code] -- enforce returning valid http codes all the way throughout? - if myResult then return myResult else return codez[501] end + if myResult then return {[code]=myResult,} else return {[501]=codez[501],} end end local function getMimeType(ext) From e01e97469f3a9dfc42ab5daa3e6a90dcb6b37102 Mon Sep 17 00:00:00 2001 From: TJ Borromeo Date: Wed, 6 May 2015 13:42:06 -0700 Subject: [PATCH 4/5] Update httpserver-header.lua --- httpserver-header.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httpserver-header.lua b/httpserver-header.lua index 599c3e5..b3f9134 100644 --- a/httpserver-header.lua +++ b/httpserver-header.lua @@ -5,10 +5,10 @@ return function (connection, code, extension) local function getHTTPStatusString(code) - local codez = {[200]="OK", [400]="Bad Request", [404]="Not Found", [501]="Not Implemented",} + local codez = {[200]="OK", [400]="Bad Request", [404]="Not Found",} local myResult = codez[code] -- enforce returning valid http codes all the way throughout? - if myResult then return {[code]=myResult,} else return {[501]=codez[501],} end + if myResult then return {[code]=myResult,} else return {[501]="Not Implemented",} end end local function getMimeType(ext) From 2672d3b46701374fccb7b84121e190ab72d2ad33 Mon Sep 17 00:00:00 2001 From: TJ Borromeo Date: Wed, 6 May 2015 13:54:21 -0700 Subject: [PATCH 5/5] Keep return type as is No need for 501 error code, as this should be returned only when needed, and will be much more efficient to not: 1.) take a table entry for the majority of cases when it isn't needed 2.) Utilize only enough memory needed to instantiate a string when it _is_ needed. --- httpserver-header.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpserver-header.lua b/httpserver-header.lua index b3f9134..5f01ef7 100644 --- a/httpserver-header.lua +++ b/httpserver-header.lua @@ -8,7 +8,7 @@ return function (connection, code, extension) local codez = {[200]="OK", [400]="Bad Request", [404]="Not Found",} local myResult = codez[code] -- enforce returning valid http codes all the way throughout? - if myResult then return {[code]=myResult,} else return {[501]="Not Implemented",} end + if myResult then return myResult else return "Not Implemented" end end local function getMimeType(ext)