@@ -93,7 +93,9 @@ def test_variables_method(search_in_file, wait_for_record):
9393 assert wait_for_record (reg , 'access.log' ) is not None , 'method POST'
9494
9595
96- def test_variables_request_uri (search_in_file , wait_for_record ):
96+ def test_variables_request_uri (
97+ findall , search_in_file , temp_dir , wait_for_record
98+ ):
9799 set_format ('$request_uri' )
98100
99101 def check_request_uri (req_uri ):
@@ -108,6 +110,103 @@ def check_request_uri(req_uri):
108110 check_request_uri ('/4%2A' )
109111 check_request_uri ('/9?q#a' )
110112
113+ # $request_uri + proxy
114+
115+ assert 'success' in client .conf (
116+ {
117+ "listeners" : {
118+ "*:8080" : {"pass" : "routes/a" },
119+ "[::1]:8081" : {"pass" : "routes/b" },
120+ },
121+ "routes" : {
122+ "a" : [
123+ {
124+ "action" : {
125+ "proxy" : "http://[::1]:8081" ,
126+ }
127+ }
128+ ],
129+ "b" : [
130+ {
131+ "action" : {
132+ "return" : 200 ,
133+ }
134+ }
135+ ],
136+ },
137+ "access_log" : {
138+ "path" : f'{ temp_dir } /access.log' ,
139+ "format" : "$remote_addr $uri $request_uri" ,
140+ },
141+ }
142+ )
143+
144+ assert search_in_file (r'::1' , 'access.log' ) is None
145+
146+ assert client .get (url = '/blah%25blah?a=b' )['status' ] == 200
147+
148+ assert (
149+ wait_for_record (fr'^::1 /blah%blah /blah%25blah\?a=b$' , 'access.log' )
150+ is not None
151+ ), 'req 8081 (proxy)'
152+ assert (
153+ search_in_file (
154+ fr'^127\.0\.0\.1 /blah%blah /blah%25blah\?a=b$' , 'access.log'
155+ )
156+ is not None
157+ ), 'req 8080'
158+
159+ # rewrite set $request_uri before proxy
160+
161+ assert 'success' in client .conf (
162+ {
163+ "a" : [
164+ {
165+ "action" : {
166+ "rewrite" : "/foo" ,
167+ "proxy" : "http://[::1]:8081" ,
168+ }
169+ }
170+ ],
171+ "b" : [
172+ {
173+ "action" : {
174+ "rewrite" : "/bar" ,
175+ "return" : 200 ,
176+ }
177+ }
178+ ],
179+ },
180+ 'routes' ,
181+ )
182+
183+ assert len (findall (r'::1' , 'access.log' )) == 1
184+
185+ assert client .get (url = '/blah%2Fblah?a=b' )['status' ] == 200
186+
187+ assert (
188+ wait_for_record (fr'^::1 /bar /bar\?a=b$' , 'access.log' ) is not None
189+ ), 'req 8081 (proxy) rewrite'
190+ assert (
191+ search_in_file (fr'^127\.0\.0\.1 /foo /foo\?a=b$' , 'access.log' )
192+ is not None
193+ ), 'req 8080 rewrite'
194+
195+ # percent-encoded rewrite
196+
197+ assert len (findall (r'::1' , 'access.log' )) == 2
198+
199+ assert 'success' in client .conf ('"/foo%2Ffoo"' , 'routes/a/0/action/rewrite' )
200+ assert client .get (url = '/blah%2Fblah?a=b' )['status' ] == 200
201+
202+ assert (
203+ wait_for_record (
204+ fr'^127\.0\.0\.1 /foo/foo /foo%2Ffoo\?a=b$' , 'access.log'
205+ )
206+ is not None
207+ ), 'req 8080 percent'
208+ assert len (findall (fr'^::1 /bar /bar\?a=b$' , 'access.log' )) == 2
209+
111210
112211def test_variables_uri (search_in_file , wait_for_record ):
113212 set_format ('$uri' )
0 commit comments