# HG changeset patch # User jbe # Date 1469478754 -7200 # Node ID 17a2b7e1c4639ee4705ff62ff7c93314236cfe62 # Parent 59a6f485176497ef21d1efea9bd8ee90af6db584 Improved function request.get_header{...} diff -r 59a6f4851764 -r 17a2b7e1c463 framework/env/request/get_header.lua --- a/framework/env/request/get_header.lua Mon Jul 25 22:27:17 2016 +0200 +++ b/framework/env/request/get_header.lua Mon Jul 25 22:32:34 2016 +0200 @@ -4,10 +4,18 @@ key -- name of header, e.g. "Authorization" ) -Returns the value of an HTTP header sent by the client. If the header occurs multiple times, the values are concatenated with a comma and zero or more space characters (e.g. "value1, value2"). +Returns the value of an HTTP header sent by the client. If the header occurs multiple times, the values are concatenated with a comma and zero or more space characters (e.g. "value1, value2"). If the header is missing, nil is returned. --]]-- function request.get_header(key) - return request._http_request.headers_csv_string[key] + local http_request = request._http_request + local values = request.headers[key] + if #values == 0 then + return nil + elseif #values == 1 then + return values[1] + else + return request._http_request.headers_csv_string[key] + end end