Module ngx-oauth.nginx
Utilities for nginx.
Functions
add_response_cookies (cookies) | Adds table of cookies to the response's Set-Cookie header. |
fail (status, message, ...) | Interrupts execution of the current request for a failure. |
format_cookie (name, value, attrs) | Formats HTTP cookie from the given arguments. |
get_cookie (name) | Returns URI-decoded value of the specified request's cookie. |
get_uri_arg (name) | Returns URI-decoded value of the specified request's URI argument (query parameter). |
log (level, message, ...) | Logs the given (formatted) message on the specified logging level . |
Functions
- add_response_cookies (cookies)
-
Adds table of cookies to the response's
Set-Cookie
header. If the header is already set, then the new cookies are appended to the existing ones.Parameters:
- cookies {string,...} The cookies to append.
See also:
- fail (status, message, ...)
-
Interrupts execution of the current request for a failure.
Logs the given error message with level
ngx.WARN
, if thestatus
is less than 500, orngx.ERR
otherwise.Sends response with the specified HTTP status and JSON body:
{ "message": "The error message" }
Parameters:
- status int The HTTP status code to send.
- message string The error message to log and send.
- ...
Arguments for string.format being applied to
message
. Nil values are replaced with#nil
.
- format_cookie (name, value, attrs)
-
Formats HTTP cookie from the given arguments.
Parameters:
- name string
- value string
- attrs {[string]=string,...} The cookie's attributes. Underscores in the attribute name are implicitly replaced with dashes.
Returns:
-
string
A cookie string.
- get_cookie (name)
-
Returns URI-decoded value of the specified request's cookie.
Parameters:
- name string The name of the cookie to get.
Returns:
-
string or nil
The cookie's value, or nil if doesn't exist.
- get_uri_arg (name)
-
Returns URI-decoded value of the specified request's URI argument
(query parameter).
Parameters:
- name string The name of the argument to get.
Returns:
-
string or nil
The argument's value, or nil if doesn't exist.
- log (level, message, ...)
-
Logs the given (formatted)
message
on the specified logginglevel
. There are 8 levels defined by ngx's constants (you can find list of them here).This module also defines convenient functions for most common levels:
log.err()
,log.warn()
,log.info()
, andlog.debug()
.Parameters:
- level int The logging level (0-8).
- message string
- ...
Arguments for string.format being applied to
message
. Nil values are replaced with#nil
.