@@ -2,7 +2,6 @@ local base = require "resty.core.base"
2
2
local get_request = base .get_request
3
3
local ffi = require " ffi"
4
4
local C = ffi .C
5
- local ffi_new = ffi .new
6
5
local ffi_str = ffi .string
7
6
local ffi_gc = ffi .gc
8
7
local FFI_OK = base .FFI_OK
@@ -33,7 +32,8 @@ typedef struct {
33
32
unsigned ipv6 :1 ;
34
33
} ngx_http_lua_resolver_ctx_t ;
35
34
36
- int ngx_http_lua_ffi_resolve (ngx_http_lua_resolver_ctx_t * ctx , const char * hostname );
35
+ int ngx_http_lua_ffi_resolve (ngx_http_lua_resolver_ctx_t * ctx ,
36
+ const char * hostname );
37
37
38
38
void ngx_http_lua_ffi_resolver_destroy (ngx_http_lua_resolver_ctx_t * ctx );
39
39
]]
@@ -47,18 +47,22 @@ local mt = {
47
47
local Ctx = ffi .metatype (" ngx_http_lua_resolver_ctx_t" , mt )
48
48
49
49
function _M .resolve (hostname , ipv4 , ipv6 )
50
- assert (type (hostname ) == " string" , " hostname must be string" )
51
- assert (ipv4 == nil or type (ipv4 ) == " boolean" , " ipv4 must be boolean or nil" )
52
- assert (ipv6 == nil or type (ipv6 ) == " boolean" , " ipv6 must be boolean or nil" )
53
-
54
50
local buf = get_string_buf (BUF_SIZE )
55
51
local buf_size = get_size_ptr ()
56
52
buf_size [0 ] = BUF_SIZE
57
53
58
- local ctx = Ctx ({get_request (), buf , buf_size })
54
+ local ctx = Ctx ()
55
+ ctx .request = get_request ()
56
+ ctx .buf = buf
57
+ ctx .buf_size = buf_size
58
+
59
+ if ipv4 == nil or ipv4 then
60
+ ctx .ipv4 = 1
61
+ end
59
62
60
- ctx .ipv4 = ipv4 == nil and 1 or ipv4
61
- ctx .ipv6 = ipv6 == nil and 0 or ipv6
63
+ if ipv6 then
64
+ ctx .ipv6 = 1
65
+ end
62
66
63
67
local rc = C .ngx_http_lua_ffi_resolve (ctx , hostname )
64
68
0 commit comments