webmcp
annotate framework/env/request/get_header.lua @ 540:d0104bb90ede
Add -lc to LDFLAGS to avoid weird problems on FreeBSD
author | jbe |
---|---|
date | Sat Oct 12 20:35:00 2019 +0200 (2019-10-12) |
parents | 6bbef2933ea5 |
children |
rev | line source |
---|---|
jbe@456 | 1 --[[-- |
jbe@456 | 2 value = -- value of header as string containing comma (and space) separated values |
jbe@456 | 3 request.get_header( |
jbe@456 | 4 key -- name of header, e.g. "Authorization" |
jbe@456 | 5 ) |
jbe@456 | 6 |
jbe@457 | 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. |
jbe@456 | 8 |
jbe@456 | 9 --]]-- |
jbe@456 | 10 |
jbe@456 | 11 function request.get_header(key) |
jbe@457 | 12 local http_request = request._http_request |
jbe@458 | 13 local values = http_request.headers[key] |
jbe@457 | 14 if #values == 0 then |
jbe@457 | 15 return nil |
jbe@457 | 16 elseif #values == 1 then |
jbe@457 | 17 return values[1] |
jbe@457 | 18 else |
jbe@458 | 19 return http_request.headers_csv_string[key] |
jbe@457 | 20 end |
jbe@456 | 21 end |