1818
1919package io .undertow .server .handlers ;
2020
21- import io .undertow .Handlers ;
2221import io .undertow .server .HttpHandler ;
2322import io .undertow .server .HttpServerExchange ;
2423import io .undertow .testutils .DefaultServer ;
3736
3837import static io .undertow .Handlers .path ;
3938import static io .undertow .Handlers .rewrite ;
39+ import static io .undertow .Handlers .setAttribute ;
4040
4141
4242/**
@@ -49,7 +49,7 @@ public class SetAttributeTestCase {
4949
5050 @ Test
5151 public void testSettingHeader () throws IOException {
52- DefaultServer .setRootHandler (Handlers . setAttribute (ResponseCodeHandler .HANDLE_200 , "%{o,Foo}" , "%U-%{q,p1}" , SetAttributeHandler .class .getClassLoader ()));
52+ DefaultServer .setRootHandler (setAttribute (ResponseCodeHandler .HANDLE_200 , "%{o,Foo}" , "%U-%{q,p1}" , SetAttributeHandler .class .getClassLoader ()));
5353
5454 TestHttpClient client = new TestHttpClient ();
5555 try {
@@ -81,10 +81,10 @@ public void testSettingHeader() throws IOException {
8181 @ Test
8282 public void testRewrite () throws IOException {
8383 DefaultServer .setRootHandler (
84- rewrite ("regex[ '/somePath/(.*)'] " , "/otherPath/$1" , getClass ().getClassLoader (), path ()
84+ rewrite ("regex( '/somePath/(.*)') " , "/otherPath/$1" , getClass ().getClassLoader (), path ()
8585 .addPrefixPath ("/otherPath" , new InfoHandler ())
8686 .addPrefixPath ("/relative" ,
87- rewrite ("path-template[ '/foo/{bar}/{woz}'] " , "/foo?bar=${bar}&woz=${woz}" , getClass ().getClassLoader (), new InfoHandler ()))
87+ rewrite ("path-template( '/foo/{bar}/{woz}') " , "/foo?bar=${bar}&woz=${woz}" , getClass ().getClassLoader (), new InfoHandler ()))
8888 ));
8989
9090 TestHttpClient client = new TestHttpClient ();
@@ -107,7 +107,53 @@ public void testRewrite() throws IOException {
107107 Assert .assertEquals (StatusCodes .OK , result .getStatusLine ().getStatusCode ());
108108 response = HttpClientUtils .readResponse (result );
109109 Assert .assertEquals ("URI: /otherPath/foo relative: /foo QS:a=b a: b" , response );
110+ } finally {
111+ client .getConnectionManager ().shutdown ();
112+ }
113+ }
110114
115+ @ Test
116+ public void testRewriteWithEncoding () throws IOException {
117+ DefaultServer .setRootHandler (
118+ rewrite ("true" , "/otherPath%{REQUEST_URL}" , getClass ().getClassLoader (), path ()
119+ .addPrefixPath ("/otherPath" , new InfoHandler ())));
120+
121+ TestHttpClient client = new TestHttpClient ();
122+ try {
123+ HttpGet get = new HttpGet (DefaultServer .getDefaultServerURL () + "/foobar" );
124+ HttpResponse result = client .execute (get );
125+ Assert .assertEquals (StatusCodes .OK , result .getStatusLine ().getStatusCode ());
126+ String response = HttpClientUtils .readResponse (result );
127+ Assert .assertEquals ("URI: /otherPath/foobar relative: /foobar QS:" , response );
128+
129+ get = new HttpGet (DefaultServer .getDefaultServerURL () + "/foo%20bar" );
130+ result = client .execute (get );
131+ Assert .assertEquals (StatusCodes .OK , result .getStatusLine ().getStatusCode ());
132+ response = HttpClientUtils .readResponse (result );
133+ Assert .assertEquals ("URI: /otherPath/foo%20bar relative: /foo bar QS:" , response );
134+ } finally {
135+ client .getConnectionManager ().shutdown ();
136+ }
137+ }
138+
139+ @ Test
140+ public void testRewriteWithEncodingNoPathMatching () throws IOException {
141+ DefaultServer .setRootHandler (
142+ rewrite ("true" , "/other%%Path%{REQUEST_URL}" , getClass ().getClassLoader (), new InfoHandler ()));
143+
144+ TestHttpClient client = new TestHttpClient ();
145+ try {
146+ HttpGet get = new HttpGet (DefaultServer .getDefaultServerURL () + "/foobar" );
147+ HttpResponse result = client .execute (get );
148+ Assert .assertEquals (StatusCodes .OK , result .getStatusLine ().getStatusCode ());
149+ String response = HttpClientUtils .readResponse (result );
150+ Assert .assertEquals ("URI: /other%25Path/foobar relative: /other%Path/foobar QS:" , response );
151+
152+ get = new HttpGet (DefaultServer .getDefaultServerURL () + "/foo%20bar" );
153+ result = client .execute (get );
154+ Assert .assertEquals (StatusCodes .OK , result .getStatusLine ().getStatusCode ());
155+ response = HttpClientUtils .readResponse (result );
156+ Assert .assertEquals ("URI: /other%25Path/foo%20bar relative: /other%Path/foo bar QS:" , response );
111157 } finally {
112158 client .getConnectionManager ().shutdown ();
113159 }
0 commit comments