@@ -82,3 +82,142 @@ GET /t?name=json&weight=20
8282-- - response_body
8383metadata add route succeed.
8484-- - error_code: 200
85+
86+
87+
88+ === TEST 2 : test host and port
89+ -- - config
90+ location / t {
91+ content_by_lua_block {
92+ local opts = {vars = {http_host = " 127.0.0.1:9080" }, host = " 127.0.0.1" }
93+ local radix = require (" resty.radixtree" )
94+ local rx = radix. new({
95+ {
96+ paths = {" /aa*" },
97+ hosts = {" 127.0.0.1:9080" },
98+ handler = function (ctx)
99+ ngx. say (" pass" )
100+ end
101+ }
102+ } )
103+ ngx. say(rx:dispatch ("/aa" , opts))
104+ }
105+ }
106+ --- request
107+ GET /t
108+ --- no_error_log
109+ [error]
110+ --- response_body
111+ pass
112+ true
113+
114+
115+
116+ === TEST 3 : test domain and port
117+ -- - config
118+ location / t {
119+ content_by_lua_block {
120+ local opts = {vars = {http_host = " www.foo.com:9080" }, host = " www.foo.com" }
121+ local radix = require (" resty.radixtree" )
122+ local rx = radix. new({
123+ {
124+ paths = {" /aa*" },
125+ hosts = " www.foo.com:9080" ,
126+ handler = function (ctx)
127+ ngx. say (" pass" )
128+ end
129+ }
130+ } )
131+ ngx. say(rx:dispatch ("/aa" , opts))
132+ }
133+ }
134+ --- request
135+ GET /t
136+ --- no_error_log
137+ [error]
138+ --- response_body
139+ pass
140+ true
141+
142+
143+
144+ === TEST 4 : match failed
145+ -- - config
146+ location / t {
147+ content_by_lua_block {
148+ local opts = {vars = {http_host = " 127.0.0.1" }, host = " 127.0.0.1" }
149+ local radix = require (" resty.radixtree" )
150+ local rx = radix. new({
151+ {
152+ paths = {" /aa*" },
153+ hosts = " 127.0.0.1:9080" ,
154+ handler = function (ctx)
155+ ngx. say (" pass" )
156+ end
157+ }
158+ } )
159+ ngx. say(rx:dispatch ("/aa" , opts))
160+ }
161+ }
162+ --- request
163+ GET /t
164+ --- no_error_log
165+ [error]
166+ --- response_body
167+ nil
168+
169+
170+
171+ === TEST 5 : match success
172+ -- - config
173+ location / t {
174+ content_by_lua_block {
175+ local opts = {vars = {http_host = " 127.0.0.1:9080" }, host = " 127.0.0.1" }
176+ local radix = require (" resty.radixtree" )
177+ local rx = radix. new({
178+ {
179+ paths = {" /aa*" },
180+ hosts = " 127.0.0.1" ,
181+ handler = function (ctx)
182+ ngx. say (" pass" )
183+ end
184+ }
185+ } )
186+ ngx. say(rx:dispatch ("/aa" , opts))
187+ }
188+ }
189+ --- request
190+ GET /t
191+ --- no_error_log
192+ [error]
193+ --- response_body
194+ pass
195+ true
196+
197+
198+
199+ === TEST 6 : match many host
200+ -- - config
201+ location / t {
202+ content_by_lua_block {
203+ local opts = {vars = {http_host = " 127.0.0.1:9980" }, host = " 127.0.0.1" }
204+ local radix = require (" resty.radixtree" )
205+ local rx = radix. new({
206+ {
207+ paths = {" /aa*" },
208+ hosts = {" www.foo.com:9080" , " 127.0.0.1:9991" , " www.bar.com:9200" , " 127.0.0.1" },
209+ handler = function (ctx)
210+ ngx. say (" pass" )
211+ end
212+ }
213+ } )
214+ ngx. say(rx:dispatch ("/aa" , opts))
215+ }
216+ }
217+ --- request
218+ GET /t
219+ --- no_error_log
220+ [error]
221+ --- response_body
222+ pass
223+ true
0 commit comments