moonbridge
changeset 180:31820816f554
Code cleanup and added "request_body_content_length" declaration in HTTP module
author | jbe |
---|---|
date | Fri Jun 19 00:44:01 2015 +0200 (2015-06-19) |
parents | 77d8fdd124e6 |
children | f0dc143f510a |
files | moonbridge_http.lua |
line diff
1.1 --- a/moonbridge_http.lua Thu Jun 18 22:38:53 2015 +0200 1.2 +++ b/moonbridge_http.lua Fri Jun 19 00:44:01 2015 +0200 1.3 @@ -246,9 +246,7 @@ 1.4 -- (raw access, but case-insensitive): 1.5 headers = setmetatable({}, { 1.6 __index = function(self, key) 1.7 - if type(key) ~= "string" then 1.8 - error("Attempted to index headers table with a non-string key") 1.9 - end 1.10 + assert(type(key) == "string", "Attempted to index headers table with a non-string key") 1.11 local lowerkey = string.lower(key) 1.12 local result = rawget(self, lowerkey) 1.13 if result == nil then 1.14 @@ -296,17 +294,19 @@ 1.15 if headers_value_nil[key] then 1.16 return nil 1.17 end 1.18 - local result = nil 1.19 local values = request.headers_csv_table[key] 1.20 if #values == 0 then 1.21 headers_value_nil[key] = true 1.22 - elseif #values == 1 then 1.23 - result = values[1] 1.24 else 1.25 - result = false 1.26 + local result 1.27 + if #values == 1 then 1.28 + result = values[1] 1.29 + else 1.30 + result = false 1.31 + end 1.32 + self[key] = result 1.33 + return result 1.34 end 1.35 - self[key] = result 1.36 - return result 1.37 end 1.38 }), 1.39 -- table mapping header field names to a flag table, 1.40 @@ -315,6 +315,7 @@ 1.41 __index = function(self, key) 1.42 local result = setmetatable({}, { 1.43 __index = function(self, key) 1.44 + assert(type(key) == "string", "Attempted to index header flag table with a non-string key") 1.45 local lowerkey = string.lower(key) 1.46 local result = rawget(self, lowerkey) or false 1.47 self[lowerkey] = result 1.48 @@ -338,18 +339,19 @@ 1.49 -- local variables to track the state: 1.50 local state = "init" -- one of: 1.51 -- "init" (initial state) 1.52 - -- "no_status_sent" (configuration complete) 1.53 + -- "no_status_sent" (request body streaming config complete) 1.54 -- "info_status_sent" (1xx status code has been sent) 1.55 -- "bodyless_status_sent" (204/304 status code has been sent) 1.56 -- "status_sent" (regular status code has been sent) 1.57 -- "headers_sent" (headers have been terminated) 1.58 -- "finished" (request has been answered completely) 1.59 -- "faulty" (I/O or protocaol error) 1.60 + local request_body_content_length -- Content-Length of request body 1.61 local close_requested = false -- "Connection: close" requested 1.62 local close_responded = false -- "Connection: close" sent 1.63 - local content_length = nil -- value of Content-Length header sent 1.64 - local chunk_parts = {} -- list of chunks to send 1.65 - local chunk_bytes = 0 -- sum of lengths of chunks to send 1.66 + local content_length = nil -- value of Content-Length header sent 1.67 + local chunk_parts = {} -- list of chunks to send 1.68 + local chunk_bytes = 0 -- sum of lengths of chunks to send 1.69 local streamed_post_params = {} -- mapping from POST field name to stream function 1.70 local streamed_post_param_patterns = {} -- list of POST field pattern and stream function pairs 1.71 -- functions to assert proper output/closing: