webmcp

changeset 457:17a2b7e1c463

Improved function request.get_header{...}
author jbe
date Mon Jul 25 22:32:34 2016 +0200 (2016-07-25)
parents 59a6f4851764
children 6bbef2933ea5
files framework/env/request/get_header.lua
line diff
     1.1 --- a/framework/env/request/get_header.lua	Mon Jul 25 22:27:17 2016 +0200
     1.2 +++ b/framework/env/request/get_header.lua	Mon Jul 25 22:32:34 2016 +0200
     1.3 @@ -4,10 +4,18 @@
     1.4    key                -- name of header, e.g. "Authorization"
     1.5  )
     1.6  
     1.7 -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").
     1.8 +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.
     1.9  
    1.10  --]]--
    1.11  
    1.12  function request.get_header(key)
    1.13 -  return request._http_request.headers_csv_string[key]
    1.14 +  local http_request = request._http_request
    1.15 +  local values = request.headers[key]
    1.16 +  if #values == 0 then
    1.17 +    return nil
    1.18 +  elseif #values == 1 then
    1.19 +    return values[1]
    1.20 +  else
    1.21 +    return request._http_request.headers_csv_string[key]
    1.22 +  end
    1.23  end

Impressum / About Us