webmcp
view framework/env/request/get_header.lua @ 527:c8e77723f9cf
Clarified "Starting your application" section in WebMCP's documentation
| author | jbe | 
|---|---|
| date | Tue Aug 22 12:20:30 2017 +0200 (2017-08-22) | 
| parents | 6bbef2933ea5 | 
| children | 
 line source
     1 --[[--
     2 value =              -- value of header as string containing comma (and space) separated values
     3 request.get_header(
     4   key                -- name of header, e.g. "Authorization"
     5 )
     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"). If the header is missing, nil is returned.
     9 --]]--
    11 function request.get_header(key)
    12   local http_request = request._http_request
    13   local values = http_request.headers[key]
    14   if #values == 0 then
    15     return nil
    16   elseif #values == 1 then
    17     return values[1]
    18   else
    19     return http_request.headers_csv_string[key]
    20   end
    21 end
