Merge commit 'c566d322b2f54889db220d733834e95d73edca38' into dev

This commit is contained in:
Théophile Diot 2025-01-17 10:18:23 +01:00
commit bc5d0a9ccb
No known key found for this signature in database
GPG key ID: FA995104A0BA376A
7 changed files with 73 additions and 9 deletions

View file

@ -49,7 +49,7 @@ env:
- TEST_NGINX_RANDOMIZE=1
- LUACHECK_VER=0.21.1
matrix:
- NGINX_VERSION=1.27.0 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f USE_PCRE2=Y
- NGINX_VERSION=1.27.1 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f USE_PCRE2=Y
- NGINX_VERSION=1.25.3 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f
services:

View file

@ -169,6 +169,7 @@ API Implemented
* [ngx.encode_base64](https://github.com/openresty/lua-nginx-module#ngxencode_base64)
* [ngx.decode_base64](https://github.com/openresty/lua-nginx-module#ngxdecode_base64)
* [ngx.decode_base64mime](https://github.com/openresty/lua-nginx-module#ngxdecode_base64mime)
[Back to TOC](#table-of-contents)

View file

@ -7,4 +7,4 @@ lib_dir=lib
doc_dir=lib
repo_link=https://github.com/openresty/lua-resty-core
main_module=lib/resty/core/base.lua
requires = luajit >= 2.1.0, nginx >= 1.13.6, ngx_http_lua = 0.10.13, openresty/lua-resty-lrucache >= 0.08
requires = luajit >= 2.1.0, nginx >= 1.27.1, ngx_http_lua = 0.10.28, openresty/lua-resty-lrucache >= 0.08

View file

@ -1,10 +1,20 @@
-- Copyright (C) Yichun Zhang. All rights reserved.
local ffi = require "ffi"
local C = ffi.C
local base = require "resty.core.base"
base.allows_subsystem('http')
local FFI_BAD_CONTEXT = base.FFI_BAD_CONTEXT
local core_response = require "resty.core.response"
local set_resp_header = core_response.set_resp_header
local get_request = base.get_request
ffi.cdef[[
int ngx_http_lua_ffi_set_resp_status_and_reason(ngx_http_request_t *r,
int status, const char *reason, size_t reason_len);
]]
local _M = { version = base.version }
@ -15,4 +25,22 @@ function _M.add_header(key, value)
end
function _M.set_status(status, reason)
local r = get_request()
if not r then
error("no request found")
end
if type(status) ~= 'number' then
status = tonumber(status)
end
local rc = C.ngx_http_lua_ffi_set_resp_status_and_reason(r, status,
reason, #reason)
if rc == FFI_BAD_CONTEXT then
error("API disabled in the current context", 2)
end
end
return _M

View file

@ -12,6 +12,7 @@ Table of Contents
* [Description](#description)
* [Methods](#methods)
* [add_header](#add_header)
* [set_status](#set_status)
* [Community](#community)
* [English Mailing List](#english-mailing-list)
* [Chinese Mailing List](#chinese-mailing-list)
@ -35,6 +36,10 @@ ngx_resp.add_header("Foo", "bar")
ngx_resp.add_header("Foo", "baz")
--> there will be two new headers in HTTP response:
--> Foo: bar and Foo: baz
ngx_resp.set(531, "user defined error")
--> the response line will be: 531 user defiend error
```
[Back to TOC](#table-of-contents)
@ -73,6 +78,15 @@ instead of appending it.
[Back to TOC](#table-of-contents)
set_status
----------
**syntax:** *ngx_resp.status(status, reason?)*
Unlike `ngx.status` which only sets the status, this function sets the response
status with an optional reason. The `reason` should be a string.
[Back to TOC](#table-of-contents)
Community
=========

View file

@ -19,22 +19,22 @@ local FREE_LIST_REF = 0
if subsystem == 'http' then
if not ngx.config
or not ngx.config.ngx_lua_version
or ngx.config.ngx_lua_version ~= 10027
or ngx.config.ngx_lua_version ~= 10028
then
error("ngx_http_lua_module 0.10.27 required")
error("ngx_http_lua_module 0.10.28 required")
end
elseif subsystem == 'stream' then
if not ngx.config
or not ngx.config.ngx_lua_version
or ngx.config.ngx_lua_version ~= 15
or ngx.config.ngx_lua_version ~= 16
then
error("ngx_stream_lua_module 0.0.15 required")
error("ngx_stream_lua_module 0.0.16 required")
end
else
error("ngx_http_lua_module 0.10.27 or "
.. "ngx_stream_lua_module 0.0.15 required")
error("ngx_http_lua_module 0.10.28 or "
.. "ngx_stream_lua_module 0.0.16 required")
end
@ -141,7 +141,7 @@ local c_buf_type = ffi.typeof("char[?]")
local _M = new_tab(0, 18)
_M.version = "0.1.30"
_M.version = "0.1.31"
_M.new_tab = new_tab
_M.clear_tab = clear_tab

View file

@ -30,6 +30,10 @@ if subsystem == "http" then
int ngx_http_lua_ffi_decode_base64(const unsigned char *src,
size_t len, unsigned char *dst,
size_t *dlen);
int ngx_http_lua_ffi_decode_base64mime(const unsigned char *src,
size_t len, unsigned char *dst,
size_t *dlen);
]]
ngx_lua_ffi_encode_base64 = C.ngx_http_lua_ffi_encode_base64
@ -51,6 +55,7 @@ elseif subsystem == "stream" then
end
local function base64_encoded_length(len, no_padding)
return no_padding and floor((len * 8 + 5) / 6) or
floor((len + 2) / 3) * 4
@ -110,6 +115,22 @@ ngx.decode_base64 = function (s)
end
ngx.decode_base64mime = function (s)
if type(s) ~= 'string' then
error("string argument only", 2)
end
local slen = #s
local dlen = base64_decoded_length(slen)
local dst = get_string_buf(dlen)
local pdlen = get_size_ptr()
local ok = C.ngx_http_lua_ffi_decode_base64mime(s, slen, dst, pdlen)
if ok == 0 then
return nil
end
return ffi_string(dst, pdlen[0])
end
return {
version = base.version
}