nginx-lua重置请求参数及常量

获取请求参数

local strider = ngx.var.arg_strider
local strider = ngx.req.get_uri_args["strider"]
当请求uri中有多个同名参数时,ngx.var.arg_xx的做法是取第一个出现的值,ngx.req_get_uri_args["xx"]的做法是返回一个table,该table里存放了该参数的所有值

重置参数

local args = ngx.req.get_uri_args()
args["userId"]="override value"
ngx.req.set_uri_args(args)

log级别常量

  1. ngx.STDERR -- 标准输出
  2. ngx.EMERG -- 紧急报错
  3. ngx.ALERT -- 报警
  4. ngx.CRIT -- 严重,系统故障,触发运维告警系统
  5. ngx.ERR -- 错误,业务不可恢复性错误
  6. ngx.WARN -- 告警,业务中可忽略错误
  7. ngx.NOTICE -- 提醒,业务比较重要信息
  8. ngx.INFO -- 信息,业务琐碎日志信息,包含不同情况判断等
  9. ngx.DEBUG -- 调试

http status code常量

1xx

  1. ngx.HTTP_CONTINUE (100) (first added in the v0.9.20 release)
  2. ngx.HTTP_SWITCHING_PROTOCOLS (101) (first added in the v0.9.20 release)

2xx

  1. ngx.HTTP_OK (200)
  2. ngx.HTTP_CREATED (201)
  3. ngx.HTTP_ACCEPTED (202) (first added in the v0.9.20 release)
  4. ngx.HTTP_NO_CONTENT (204) (first added in the v0.9.20 release)
  5. ngx.HTTP_PARTIAL_CONTENT (206) (first added in the v0.9.20 release)

3xx

  1. ngx.HTTP_SPECIAL_RESPONSE (300)
  2. ngx.HTTP_MOVED_PERMANENTLY (301)
  3. ngx.HTTP_MOVED_TEMPORARILY (302)
  4. ngx.HTTP_SEE_OTHER (303)
  5. ngx.HTTP_NOT_MODIFIED (304)
  6. ngx.HTTP_TEMPORARY_REDIRECT (307) (first added in the v0.9.20 release)

4xx

  1. ngx.HTTP_BAD_REQUEST (400)
  2. ngx.HTTP_UNAUTHORIZED (401)
  3. ngx.HTTP_PAYMENT_REQUIRED (402) (first added in the v0.9.20 release)
  4. ngx.HTTP_FORBIDDEN (403)
  5. ngx.HTTP_NOT_FOUND (404)
  6. ngx.HTTP_NOT_ALLOWED (405)
  7. ngx.HTTP_NOT_ACCEPTABLE (406) (first added in the v0.9.20 release)
  8. ngx.HTTP_REQUEST_TIMEOUT (408) (first added in the v0.9.20 release)
  9. ngx.HTTP_CONFLICT (409) (first added in the v0.9.20 release)
  10. ngx.HTTP_GONE (410)
  11. ngx.HTTP_UPGRADE_REQUIRED (426) (first added in the v0.9.20 release)
  12. ngx.HTTP_TOO_MANY_REQUESTS (429) (first added in the v0.9.20 release)
  13. ngx.HTTP_CLOSE (444) (first added in the v0.9.20 release)
  14. ngx.HTTP_ILLEGAL (451) (first added in the v0.9.20 release)

5xx

  1. ngx.HTTP_INTERNAL_SERVER_ERROR (500)
  2. ngx.HTTP_METHOD_NOT_IMPLEMENTED (501)
  3. ngx.HTTP_BAD_GATEWAY (502) (first added in the v0.9.20 release)
  4. ngx.HTTP_SERVICE_UNAVAILABLE (503)
  5. ngx.HTTP_GATEWAY_TIMEOUT (504) (first added in the v0.3.1rc38 release)
  6. ngx.HTTP_VERSION_NOT_SUPPORTED (505) (first added in the v0.9.20 release)
  7. ngx.HTTP_INSUFFICIENT_STORAGE (507) (first added in the v0.9.20 release)