refactored Request to use new HttpURI
This commit is contained in:
parent
30123607c6
commit
22e57ef7b7
|
@ -394,6 +394,12 @@ public class HttpURI
|
|||
state=State.PATH;
|
||||
break;
|
||||
}
|
||||
case ';':
|
||||
{
|
||||
// multiple parameters
|
||||
m=i+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -624,18 +630,55 @@ public class HttpURI
|
|||
return toString().equals(o.toString());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setScheme(String scheme)
|
||||
{
|
||||
_scheme=scheme;
|
||||
_uri=null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param host
|
||||
* @param port
|
||||
*/
|
||||
public void setAuth(String host, int port)
|
||||
public void setAuthority(String host, int port)
|
||||
{
|
||||
_host=host;
|
||||
_port=port;
|
||||
_uri=null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param path
|
||||
*/
|
||||
public void setPath(String path)
|
||||
{
|
||||
_uri=null;
|
||||
_path=path;
|
||||
_decodedPath=null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setPathQuery(String path)
|
||||
{
|
||||
_uri=null;
|
||||
_path=null;
|
||||
_decodedPath=null;
|
||||
_param=null;
|
||||
_fragment=null;
|
||||
if (path!=null)
|
||||
parse(State.PATH,path,0,path.length());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setQuery(String query)
|
||||
{
|
||||
_query=query;
|
||||
_uri=null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public URI toURI() throws URISyntaxException
|
||||
{
|
||||
|
@ -657,4 +700,6 @@ public class HttpURI
|
|||
return _host+":"+_port;
|
||||
return _host;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -246,4 +246,49 @@ public class HttpURITest
|
|||
assertEquals("jsessionid=12345",uri.getParam());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMutableURI()
|
||||
{
|
||||
HttpURI uri = new HttpURI("/foo/bar");
|
||||
assertEquals("/foo/bar",uri.toString());
|
||||
assertEquals("/foo/bar",uri.getPath());
|
||||
assertEquals("/foo/bar",uri.getDecodedPath());
|
||||
|
||||
uri.setScheme("http");
|
||||
assertEquals("http:/foo/bar",uri.toString());
|
||||
assertEquals("/foo/bar",uri.getPath());
|
||||
assertEquals("/foo/bar",uri.getDecodedPath());
|
||||
|
||||
uri.setAuthority("host",0);
|
||||
assertEquals("http://host/foo/bar",uri.toString());
|
||||
assertEquals("/foo/bar",uri.getPath());
|
||||
assertEquals("/foo/bar",uri.getDecodedPath());
|
||||
|
||||
uri.setAuthority("host",8888);
|
||||
assertEquals("http://host:8888/foo/bar",uri.toString());
|
||||
assertEquals("/foo/bar",uri.getPath());
|
||||
assertEquals("/foo/bar",uri.getDecodedPath());
|
||||
|
||||
uri.setPathQuery("/f%30%30;p0/bar;p1;p2");
|
||||
assertEquals("http://host:8888/f%30%30;p0/bar;p1;p2",uri.toString());
|
||||
assertEquals("/f%30%30;p0/bar;p1;p2",uri.getPath());
|
||||
assertEquals("/f00/bar",uri.getDecodedPath());
|
||||
assertEquals("p2",uri.getParam());
|
||||
assertEquals(null,uri.getQuery());
|
||||
|
||||
uri.setPathQuery("/f%30%30;p0/bar;p1;p2?name=value");
|
||||
assertEquals("http://host:8888/f%30%30;p0/bar;p1;p2?name=value",uri.toString());
|
||||
assertEquals("/f%30%30;p0/bar;p1;p2",uri.getPath());
|
||||
assertEquals("/f00/bar",uri.getDecodedPath());
|
||||
assertEquals("p2",uri.getParam());
|
||||
assertEquals("name=value",uri.getQuery());
|
||||
|
||||
uri.setQuery("other=123456");
|
||||
assertEquals("http://host:8888/f%30%30;p0/bar;p1;p2?other=123456",uri.toString());
|
||||
assertEquals("/f%30%30;p0/bar;p1;p2",uri.getPath());
|
||||
assertEquals("/f00/bar",uri.getDecodedPath());
|
||||
assertEquals("p2",uri.getParam());
|
||||
assertEquals("other=123456",uri.getQuery());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class CompactPathRule extends Rule implements Rule.ApplyURI
|
|||
String uri = request.getRequestURI();
|
||||
if (uri.startsWith("/"))
|
||||
uri = URIUtil.compactPath(uri);
|
||||
request.setRequestURI(uri);
|
||||
request.setURIPathQuery(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -88,7 +88,7 @@ public class RewritePatternRule extends PatternRule implements Rule.ApplyURI
|
|||
{
|
||||
if (_query == null)
|
||||
{
|
||||
request.setRequestURI(newURI);
|
||||
request.setURIPathQuery(newURI);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -97,9 +97,7 @@ public class RewritePatternRule extends PatternRule implements Rule.ApplyURI
|
|||
queryString = queryString + "&" + _query;
|
||||
else
|
||||
queryString = _query;
|
||||
HttpURI uri = new HttpURI(newURI + "?" + queryString);
|
||||
request.setUri(uri);
|
||||
request.setRequestURI(newURI);
|
||||
request.setURIPathQuery(newURI);
|
||||
request.setQueryString(queryString);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ public class RewriteRegexRule extends RegexRule implements Rule.ApplyURI
|
|||
{
|
||||
if (_query==null)
|
||||
{
|
||||
request.setRequestURI(newURI);
|
||||
request.setURIPathQuery(newURI);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -108,9 +108,7 @@ public class RewriteRegexRule extends RegexRule implements Rule.ApplyURI
|
|||
|
||||
if (!_queryGroup && request.getQueryString()!=null)
|
||||
query=request.getQueryString()+"&"+query;
|
||||
HttpURI uri=new HttpURI(newURI+"?"+query);
|
||||
request.setUri(uri);
|
||||
request.setRequestURI(newURI);
|
||||
request.setURIPathQuery(newURI);
|
||||
request.setQueryString(query);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ public class RuleContainer extends Rule
|
|||
if (rule instanceof Rule.ApplyURI)
|
||||
((Rule.ApplyURI)rule).applyURI((Request)request,((Request)request).getRequestURI(), encoded);
|
||||
else
|
||||
((Request)request).setRequestURI(encoded);
|
||||
((Request)request).setURIPathQuery(encoded);
|
||||
}
|
||||
|
||||
if (_rewritePathInfo)
|
||||
|
|
|
@ -73,11 +73,11 @@ public class ForwardedSchemeHeaderRuleTest extends AbstractRuleTestCase
|
|||
_rule.matchAndApply("/",_request,_response);
|
||||
assertEquals("https",_request.getScheme());
|
||||
|
||||
_request.setScheme(null);
|
||||
_request.setScheme("other");
|
||||
// header value doesn't match rule's value
|
||||
setRequestHeader("Front-End-Https", "off");
|
||||
_rule.matchAndApply("/",_request,_response);
|
||||
assertEquals(null,_request.getScheme());
|
||||
assertEquals("other",_request.getScheme());
|
||||
|
||||
_request.setScheme(null);
|
||||
// header value can be any value
|
||||
|
|
|
@ -25,6 +25,10 @@ import java.io.IOException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http.MetaData;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -138,7 +142,7 @@ public class PatternRuleTest
|
|||
new Request(null,null)
|
||||
{
|
||||
{
|
||||
setRequestURI(uri);
|
||||
setMetaData(new MetaData.Request("GET",new HttpURI(uri),HttpVersion.HTTP_1_0,new HttpFields()));
|
||||
}
|
||||
}, null
|
||||
);
|
||||
|
|
|
@ -85,7 +85,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_handler.setOriginalPathAttribute("/before");
|
||||
_handler.setRewriteRequestURI(true);
|
||||
_handler.setRewritePathInfo(true);
|
||||
_request.setRequestURI("/xxx/bar");
|
||||
_request.setURIPathQuery("/xxx/bar");
|
||||
_request.setPathInfo("/xxx/bar");
|
||||
_handler.handle("/xxx/bar",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
|
@ -99,7 +99,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_handler.setOriginalPathAttribute("/before");
|
||||
_handler.setRewriteRequestURI(false);
|
||||
_handler.setRewritePathInfo(false);
|
||||
_request.setRequestURI("/foo/bar");
|
||||
_request.setURIPathQuery("/foo/bar");
|
||||
_request.setPathInfo("/foo/bar");
|
||||
|
||||
_handler.handle("/foo/bar",_request,_request, _response);
|
||||
|
@ -112,7 +112,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_response.setStatus(200);
|
||||
_request.setHandled(false);
|
||||
_handler.setOriginalPathAttribute(null);
|
||||
_request.setRequestURI("/aaa/bar");
|
||||
_request.setURIPathQuery("/aaa/bar");
|
||||
_request.setPathInfo("/aaa/bar");
|
||||
_handler.handle("/aaa/bar",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
|
@ -126,7 +126,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_handler.setOriginalPathAttribute("before");
|
||||
_handler.setRewriteRequestURI(true);
|
||||
_handler.setRewritePathInfo(true);
|
||||
_request.setRequestURI("/aaa/bar");
|
||||
_request.setURIPathQuery("/aaa/bar");
|
||||
_request.setPathInfo("/aaa/bar");
|
||||
_handler.handle("/aaa/bar",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
|
@ -138,7 +138,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_response.setStatus(200);
|
||||
_request.setHandled(false);
|
||||
_rule2.setTerminating(true);
|
||||
_request.setRequestURI("/aaa/bar");
|
||||
_request.setURIPathQuery("/aaa/bar");
|
||||
_request.setPathInfo("/aaa/bar");
|
||||
_handler.handle("/aaa/bar",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
|
@ -154,7 +154,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_request.setAttribute("target",null);
|
||||
_request.setAttribute("URI",null);
|
||||
_request.setAttribute("info",null);
|
||||
_request.setRequestURI("/aaa/bar");
|
||||
_request.setURIPathQuery("/aaa/bar");
|
||||
_request.setPathInfo("/aaa/bar");
|
||||
_handler.handle("/aaa/bar",_request,_request, _response);
|
||||
assertEquals(200,_response.getStatus());
|
||||
|
@ -174,7 +174,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_handler.setOriginalPathAttribute("/before");
|
||||
_handler.setRewriteRequestURI(true);
|
||||
_handler.setRewritePathInfo(false);
|
||||
_request.setRequestURI("/ccc/x%20y");
|
||||
_request.setURIPathQuery("/ccc/x%20y");
|
||||
_request.setPathInfo("/ccc/x y");
|
||||
_handler.handle("/ccc/x y",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
|
@ -193,7 +193,7 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
_handler.setOriginalPathAttribute("/before");
|
||||
_handler.setRewriteRequestURI(true);
|
||||
_handler.setRewritePathInfo(false);
|
||||
_request.setRequestURI("/xxx/x%20y");
|
||||
_request.setURIPathQuery("/xxx/x%20y");
|
||||
_request.setPathInfo("/xxx/x y");
|
||||
_handler.handle("/xxx/x y",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
|
|
|
@ -88,7 +88,7 @@ public class RewritePatternRuleTest extends AbstractRuleTestCase
|
|||
{
|
||||
String replacement = "/replace";
|
||||
String queryString = "request=parameter";
|
||||
_request.setUri(new HttpURI("/old/context"));
|
||||
_request.setURIPathQuery("/old/context");
|
||||
_request.setQueryString(queryString);
|
||||
|
||||
RewritePatternRule rewritePatternRule = new RewritePatternRule();
|
||||
|
@ -111,7 +111,7 @@ public class RewritePatternRuleTest extends AbstractRuleTestCase
|
|||
String[] split = replacement.split("\\?", 2);
|
||||
String path = split[0];
|
||||
String queryString = split[1];
|
||||
_request.setUri(new HttpURI("/old/context"));
|
||||
_request.setURIPathQuery("/old/context");
|
||||
_request.setQueryString(requestQueryString);
|
||||
|
||||
RewritePatternRule rewritePatternRule = new RewritePatternRule();
|
||||
|
|
|
@ -66,15 +66,13 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase
|
|||
for (String[] test : _tests)
|
||||
{
|
||||
reset();
|
||||
_request.setRequestURI(null);
|
||||
_request.setURIPathQuery(null);
|
||||
|
||||
String t=test[0]+"?"+test[1]+">"+test[2]+"|"+test[3];
|
||||
_rule.setRegex(test[2]);
|
||||
_rule.setReplacement(test[3]);
|
||||
|
||||
_request.setUri(new HttpURI(test[0]+(test[1]==null?"":("?"+test[1]))));
|
||||
_request.getRequestURI();
|
||||
|
||||
_request.setURIPathQuery(test[0]+(test[1]==null?"":("?"+test[1])));
|
||||
|
||||
String result = _rule.matchAndApply(test[0], _request, _response);
|
||||
assertEquals(t, test[4], result);
|
||||
|
@ -110,7 +108,7 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase
|
|||
_rule.setRegex(test[2]);
|
||||
_rule.setReplacement(test[3]);
|
||||
|
||||
_request.setRequestURI(test[0]);
|
||||
_request.setURIPathQuery(test[0]);
|
||||
_request.setQueryString(test[1]);
|
||||
_request.getAttributes().clearAttributes();
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
|
|||
public void testValidUrl() throws Exception
|
||||
{
|
||||
_rule.setCode("404");
|
||||
_request.setRequestURI("/valid/uri.html");
|
||||
_request.setURIPathQuery("/valid/uri.html");
|
||||
|
||||
_rule.matchAndApply(_request.getRequestURI(), _request, _response);
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
|
|||
public void testInvalidUrl() throws Exception
|
||||
{
|
||||
_rule.setCode("404");
|
||||
_request.setRequestURI("/invalid%0c/uri.html");
|
||||
_request.setURIPathQuery("/invalid%0c/uri.html");
|
||||
|
||||
String result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
|
|||
{
|
||||
_rule.setCode("405");
|
||||
_rule.setReason("foo");
|
||||
_request.setRequestURI("/%00/");
|
||||
_request.setURIPathQuery("/%00/");
|
||||
|
||||
String result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
|
|||
{
|
||||
_rule.setCode("405");
|
||||
_rule.setReason("foo");
|
||||
_request.setRequestURI("/jsp/bean1.jsp%00");
|
||||
_request.setURIPathQuery("/jsp/bean1.jsp%00");
|
||||
|
||||
String result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
|
|||
{
|
||||
_rule.setCode("405");
|
||||
_rule.setReason("foo");
|
||||
_request.setRequestURI("/jsp/shamrock-%00%E2%98%98.jsp");
|
||||
_request.setURIPathQuery("/jsp/shamrock-%00%E2%98%98.jsp");
|
||||
|
||||
String result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
|
|||
{
|
||||
_rule.setCode("405");
|
||||
_rule.setReason("foo");
|
||||
_request.setRequestURI("/jsp/shamrock-%E2%98%98.jsp");
|
||||
_request.setURIPathQuery("/jsp/shamrock-%E2%98%98.jsp");
|
||||
|
||||
String result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
_fooContainerRule.setRules(new Rule[] { _fooRule });
|
||||
|
||||
start(false);
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
|
||||
_handler.setServer(_server);
|
||||
_handler.start();
|
||||
|
@ -58,7 +58,7 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
@Test
|
||||
public void testArbitraryHost() throws Exception
|
||||
{
|
||||
_request.setServerName("cheese.com");
|
||||
_request.setAuthority("cheese.com",0);
|
||||
_handler.setRules(new Rule[] { _rule, _fooContainerRule });
|
||||
handleRequest();
|
||||
assertEquals("{_rule, _fooContainerRule, Host: cheese.com}: applied _rule", "/rule/bar", _request.getRequestURI());
|
||||
|
@ -67,7 +67,7 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
@Test
|
||||
public void testVirtualHost() throws Exception
|
||||
{
|
||||
_request.setServerName("foo.com");
|
||||
_request.setAuthority("foo.com",0);
|
||||
_handler.setRules(new Rule[] { _fooContainerRule });
|
||||
handleRequest();
|
||||
assertEquals("{_fooContainerRule, Host: foo.com}: applied _fooRule", "/cheese/fooRule", _request.getRequestURI());
|
||||
|
@ -76,8 +76,8 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
@Test
|
||||
public void testCascadingRules() throws Exception
|
||||
{
|
||||
_request.setServerName("foo.com");
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setAuthority("foo.com",0);
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
|
||||
_rule.setTerminating(false);
|
||||
_fooRule.setTerminating(false);
|
||||
|
@ -87,17 +87,17 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
handleRequest();
|
||||
assertEquals("{_rule, _fooContainerRule}: applied _rule, didn't match _fooRule", "/rule/bar", _request.getRequestURI());
|
||||
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
_handler.setRules(new Rule[] { _fooContainerRule, _rule });
|
||||
handleRequest();
|
||||
assertEquals("{_fooContainerRule, _rule}: applied _fooRule, _rule","/rule/fooRule", _request.getRequestURI());
|
||||
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
_fooRule.setTerminating(true);
|
||||
handleRequest();
|
||||
assertEquals("{_fooContainerRule, _rule}: (_fooRule is terminating); applied _fooRule, _rule", "/rule/fooRule", _request.getRequestURI());
|
||||
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
_fooRule.setTerminating(false);
|
||||
_fooContainerRule.setTerminating(true);
|
||||
handleRequest();
|
||||
|
@ -107,7 +107,7 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
@Test
|
||||
public void testCaseInsensitiveHostname() throws Exception
|
||||
{
|
||||
_request.setServerName("Foo.com");
|
||||
_request.setAuthority("Foo.com",0);
|
||||
_fooContainerRule.setVirtualHosts(new String[] {"foo.com"} );
|
||||
|
||||
_handler.setRules(new Rule[]{ _fooContainerRule });
|
||||
|
@ -118,21 +118,21 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
@Test
|
||||
public void testEmptyVirtualHost() throws Exception
|
||||
{
|
||||
_request.setServerName("cheese.com");
|
||||
_request.setAuthority("cheese.com",0);
|
||||
|
||||
_handler.setRules(new Rule[] { _fooContainerRule });
|
||||
_fooContainerRule.setVirtualHosts(null);
|
||||
handleRequest();
|
||||
assertEquals("{_fooContainerRule: virtual hosts array is null, Host: cheese.com}: apply _fooRule", "/cheese/fooRule", _request.getRequestURI());
|
||||
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
_fooContainerRule.setVirtualHosts(new String[] {});
|
||||
handleRequest();
|
||||
assertEquals("{_fooContainerRule: virtual hosts array is empty, Host: cheese.com}: apply _fooRule", "/cheese/fooRule", _request.getRequestURI());
|
||||
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
_fooContainerRule.setVirtualHosts(new String[] {null});
|
||||
handleRequest();
|
||||
assertEquals("{_fooContainerRule: virtual host is null, Host: cheese.com}: apply _fooRule", "/cheese/fooRule", _request.getRequestURI());
|
||||
|
@ -142,14 +142,14 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
@Test
|
||||
public void testMultipleVirtualHosts() throws Exception
|
||||
{
|
||||
_request.setServerName("foo.com");
|
||||
_request.setAuthority("foo.com",0);
|
||||
_handler.setRules(new Rule[] {_fooContainerRule });
|
||||
|
||||
_fooContainerRule.setVirtualHosts(new String[]{ "cheese.com" });
|
||||
handleRequest();
|
||||
assertEquals("{_fooContainerRule: vhosts[cheese.com], Host: foo.com}: no effect", "/cheese/bar", _request.getRequestURI());
|
||||
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
_fooContainerRule.addVirtualHost( "foo.com" );
|
||||
handleRequest();
|
||||
assertEquals("{_fooContainerRule: vhosts[cheese.com, foo.com], Host: foo.com}: apply _fooRule", "/cheese/fooRule", _request.getRequestURI());
|
||||
|
@ -182,8 +182,8 @@ public class VirtualHostRuleContainerTest extends AbstractRuleTestCase
|
|||
|
||||
for(String host: requestHosts)
|
||||
{
|
||||
_request.setServerName(host);
|
||||
_request.setRequestURI("/cheese/bar");
|
||||
_request.setAuthority(host,0);
|
||||
_request.setURIPathQuery("/cheese/bar");
|
||||
handleRequest();
|
||||
if(succeed)
|
||||
assertEquals("{_fooContainerRule, Host: "+host+"}: should apply _fooRule", "/cheese/fooRule", _request.getRequestURI());
|
||||
|
|
|
@ -180,7 +180,7 @@ public class Dispatcher implements RequestDispatcher
|
|||
attr._servletPath=old_servlet_path;
|
||||
}
|
||||
|
||||
baseRequest.setRequestURI(_uri);
|
||||
baseRequest.setURIPathQuery(_uri);
|
||||
baseRequest.setContextPath(_contextHandler.getContextPath());
|
||||
baseRequest.setServletPath(null);
|
||||
baseRequest.setPathInfo(_uri);
|
||||
|
@ -197,7 +197,7 @@ public class Dispatcher implements RequestDispatcher
|
|||
finally
|
||||
{
|
||||
baseRequest.setHandled(old_handled);
|
||||
baseRequest.setRequestURI(old_uri);
|
||||
baseRequest.setURIPathQuery(old_uri);
|
||||
baseRequest.setContextPath(old_context_path);
|
||||
baseRequest.setServletPath(old_servlet_path);
|
||||
baseRequest.setPathInfo(old_path_info);
|
||||
|
|
|
@ -226,21 +226,19 @@ public class ForwardedRequestCustomizer implements Customizer
|
|||
{
|
||||
// Update host header
|
||||
httpFields.put(_hostHeader);
|
||||
request.setServerName(_hostHeader.getHost());
|
||||
request.setServerPort(_hostHeader.getPort());
|
||||
request.setAuthority(_hostHeader.getHost(),_hostHeader.getPort());
|
||||
}
|
||||
else if (forwardedHost != null)
|
||||
{
|
||||
// Update host header
|
||||
HostPortHttpField auth = new HostPortHttpField(forwardedHost);
|
||||
httpFields.put(auth);
|
||||
request.setServerName(auth.getHost());
|
||||
request.setServerPort(auth.getPort());
|
||||
request.setAuthority(auth.getHost(),auth.getPort());
|
||||
}
|
||||
else if (forwardedServer != null)
|
||||
{
|
||||
// Use provided server name
|
||||
request.setServerName(forwardedServer);
|
||||
request.setAuthority(forwardedServer,request.getServerPort());
|
||||
}
|
||||
|
||||
if (forwardedFor != null)
|
||||
|
|
|
@ -62,10 +62,6 @@ public class HostHeaderCustomizer implements HttpConfiguration.Customizer
|
|||
public void customize(Connector connector, HttpConfiguration channelConfig, Request request)
|
||||
{
|
||||
if (request.getHeader("Host") == null)
|
||||
{
|
||||
request.setServerName(serverName);
|
||||
if (serverPort > 0)
|
||||
request.setServerPort(serverPort);
|
||||
}
|
||||
request.setAuthority(serverName,serverPort); // TODO set the field as well?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,8 +105,7 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl
|
|||
_metadata.setMethod(HttpMethod.CONNECT.asString());
|
||||
Request request = getRequest();
|
||||
request.setAttribute("PROXY", protocol);
|
||||
request.setServerName(sAddr);
|
||||
request.setServerPort(dPort);
|
||||
request.setAuthority(sAddr,dPort);
|
||||
request.setRemoteAddr(InetSocketAddress.createUnresolved(sAddr,sPort));
|
||||
}
|
||||
|
||||
|
@ -127,7 +126,7 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl
|
|||
if (!_uri.isAbsolute() && field instanceof HostPortHttpField)
|
||||
{
|
||||
HostPortHttpField hp = (HostPortHttpField)field;
|
||||
_uri.setAuth(hp.getHost(),hp.getPort());
|
||||
_uri.setAuthority(hp.getHost(),hp.getPort());
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ import org.eclipse.jetty.http.HttpField;
|
|||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpScheme;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
|
@ -133,6 +134,11 @@ public class Request implements HttpServletRequest
|
|||
private final HttpInput _input;
|
||||
|
||||
private MetaData.Request _metadata;
|
||||
|
||||
private String _contextPath;
|
||||
private String _servletPath;
|
||||
private String _pathInfo;
|
||||
|
||||
private boolean _secure;
|
||||
private boolean _asyncSupported = true;
|
||||
private boolean _newContext;
|
||||
|
@ -144,32 +150,22 @@ public class Request implements HttpServletRequest
|
|||
private Authentication _authentication;
|
||||
private String _characterEncoding;
|
||||
private ContextHandler.Context _context;
|
||||
private String _contextPath;
|
||||
private CookieCutter _cookies;
|
||||
private DispatcherType _dispatcherType;
|
||||
private int _inputState = __NONE;
|
||||
private String _httpMethod;
|
||||
private MultiMap<String> _queryParameters;
|
||||
private MultiMap<String> _contentParameters;
|
||||
private MultiMap<String> _parameters;
|
||||
private String _pathInfo;
|
||||
private int _serverPort;
|
||||
private String _queryEncoding;
|
||||
private String _queryString;
|
||||
private BufferedReader _reader;
|
||||
private String _readerEncoding;
|
||||
private InetSocketAddress _remote;
|
||||
private String _requestedSessionId;
|
||||
private String _requestURI;
|
||||
private Map<Object, HttpSession> _savedNewSessions;
|
||||
private String _scheme = URIUtil.HTTP;
|
||||
private UserIdentity.Scope _scope;
|
||||
private String _serverName;
|
||||
private String _servletPath;
|
||||
private HttpSession _session;
|
||||
private SessionManager _sessionManager;
|
||||
private long _timeStamp;
|
||||
private HttpURI _uri;
|
||||
private MultiPartInputStreamParser _multiPartInputStream; //if the request is a multi-part mime
|
||||
private AsyncContextState _async;
|
||||
|
||||
|
@ -227,17 +223,17 @@ public class Request implements HttpServletRequest
|
|||
private MultiMap<String> extractQueryParameters()
|
||||
{
|
||||
MultiMap<String> result = new MultiMap<>();
|
||||
if (_uri != null && _uri.hasQuery())
|
||||
if (_metadata.getURI() != null && _metadata.getURI().hasQuery())
|
||||
{
|
||||
if (_queryEncoding == null)
|
||||
{
|
||||
_uri.decodeQueryTo(result);
|
||||
_metadata.getURI().decodeQueryTo(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
_uri.decodeQueryTo(result, _queryEncoding);
|
||||
_metadata.getURI().decodeQueryTo(result, _queryEncoding);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
|
@ -763,6 +759,21 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public String getLocalAddr()
|
||||
{
|
||||
if (_channel==null)
|
||||
{
|
||||
try
|
||||
{
|
||||
String name =InetAddress.getLocalHost().getHostAddress();
|
||||
if (StringUtil.ALL_INTERFACES.equals(name))
|
||||
return null;
|
||||
return name;
|
||||
}
|
||||
catch (java.net.UnknownHostException e)
|
||||
{
|
||||
LOG.ignore(e);
|
||||
}
|
||||
}
|
||||
|
||||
InetSocketAddress local=_channel.getLocalAddress();
|
||||
if (local==null)
|
||||
return "";
|
||||
|
@ -779,6 +790,20 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public String getLocalName()
|
||||
{
|
||||
if (_channel==null)
|
||||
{
|
||||
try
|
||||
{
|
||||
String name =InetAddress.getLocalHost().getHostName();
|
||||
if (StringUtil.ALL_INTERFACES.equals(name))
|
||||
return null;
|
||||
return name;
|
||||
}
|
||||
catch (java.net.UnknownHostException e)
|
||||
{
|
||||
LOG.ignore(e);
|
||||
}
|
||||
}
|
||||
InetSocketAddress local=_channel.getLocalAddress();
|
||||
return local.getHostString();
|
||||
}
|
||||
|
@ -790,6 +815,8 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public int getLocalPort()
|
||||
{
|
||||
if (_channel==null)
|
||||
return 0;
|
||||
InetSocketAddress local=_channel.getLocalAddress();
|
||||
return local.getPort();
|
||||
}
|
||||
|
@ -801,7 +828,7 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public String getMethod()
|
||||
{
|
||||
return _httpMethod;
|
||||
return _metadata.getMethod();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -947,9 +974,7 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public String getQueryString()
|
||||
{
|
||||
if (_queryString == null && _uri != null)
|
||||
_queryString = _uri.getQuery();
|
||||
return _queryString;
|
||||
return _metadata.getURI().getQuery();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1116,9 +1141,7 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public String getRequestURI()
|
||||
{
|
||||
if (_requestURI == null && _uri != null)
|
||||
_requestURI = _uri.getPath();
|
||||
return _requestURI;
|
||||
return _metadata.getURI().getPath();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1165,7 +1188,8 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public String getScheme()
|
||||
{
|
||||
return _scheme;
|
||||
String scheme=_metadata.getURI().getScheme();
|
||||
return scheme==null?HttpScheme.HTTP.asString():scheme;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1175,52 +1199,45 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public String getServerName()
|
||||
{
|
||||
String name = _metadata.getURI().getHost();
|
||||
|
||||
// Return already determined host
|
||||
if (_serverName != null)
|
||||
return _serverName;
|
||||
if (name != null)
|
||||
return name;
|
||||
|
||||
if (_uri == null)
|
||||
throw new IllegalStateException("No uri");
|
||||
|
||||
// Return host from absolute URI
|
||||
_serverName = _uri.getHost();
|
||||
if (_serverName != null)
|
||||
{
|
||||
_serverPort = _uri.getPort();
|
||||
return _serverName;
|
||||
}
|
||||
return findServerName();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private String findServerName()
|
||||
{
|
||||
// Return host from header field
|
||||
HttpField host = _metadata.getFields().getField(HttpHeader.HOST);
|
||||
if (host!=null)
|
||||
{
|
||||
// TODO is this needed now?
|
||||
HostPortHttpField authority = (host instanceof HostPortHttpField)
|
||||
?((HostPortHttpField)host)
|
||||
:new HostPortHttpField(host.getValue());
|
||||
_serverName=authority.getHost();
|
||||
_serverPort=authority.getPort();
|
||||
return _serverName;
|
||||
_metadata.getURI().setAuthority(authority.getHost(),authority.getPort());
|
||||
return authority.getHost();
|
||||
}
|
||||
|
||||
// Return host from connection
|
||||
if (_channel != null)
|
||||
{
|
||||
_serverName = getLocalName();
|
||||
_serverPort = getLocalPort();
|
||||
if (_serverName != null && !StringUtil.ALL_INTERFACES.equals(_serverName))
|
||||
return _serverName;
|
||||
}
|
||||
String name=getLocalName();
|
||||
if (name != null)
|
||||
return name;
|
||||
|
||||
// Return the local host
|
||||
try
|
||||
{
|
||||
_serverName = InetAddress.getLocalHost().getHostAddress();
|
||||
return InetAddress.getLocalHost().getHostAddress();
|
||||
}
|
||||
catch (java.net.UnknownHostException e)
|
||||
{
|
||||
LOG.ignore(e);
|
||||
}
|
||||
return _serverName;
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1230,13 +1247,11 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public int getServerPort()
|
||||
{
|
||||
// If we have no port and have not decoded a server name
|
||||
if (_serverPort <= 0 && _serverName == null)
|
||||
// decode a server name, which will set the port if it can
|
||||
getServerName();
|
||||
|
||||
HttpURI uri = _metadata.getURI();
|
||||
int port = (uri.getHost()==null)?findServerPort():uri.getPort();
|
||||
|
||||
// If no port specified, return the default port for the scheme
|
||||
if (_serverPort <= 0)
|
||||
if (port <= 0)
|
||||
{
|
||||
if (getScheme().equalsIgnoreCase(URIUtil.HTTPS))
|
||||
return 443;
|
||||
|
@ -1244,9 +1259,31 @@ public class Request implements HttpServletRequest
|
|||
}
|
||||
|
||||
// return a specific port
|
||||
return _serverPort;
|
||||
return port;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private int findServerPort()
|
||||
{
|
||||
// Return host from header field
|
||||
HttpField host = _metadata.getFields().getField(HttpHeader.HOST);
|
||||
if (host!=null)
|
||||
{
|
||||
// TODO is this needed now?
|
||||
HostPortHttpField authority = (host instanceof HostPortHttpField)
|
||||
?((HostPortHttpField)host)
|
||||
:new HostPortHttpField(host.getValue());
|
||||
_metadata.getURI().setAuthority(authority.getHost(),authority.getPort());
|
||||
return authority.getPort();
|
||||
}
|
||||
|
||||
// Return host from connection
|
||||
if (_channel != null)
|
||||
return getLocalPort();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public ServletContext getServletContext()
|
||||
|
@ -1373,7 +1410,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public HttpURI getUri()
|
||||
{
|
||||
return _uri;
|
||||
return _metadata.getURI();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1539,33 +1576,22 @@ public class Request implements HttpServletRequest
|
|||
setMethod(request.getMethod());
|
||||
HttpURI uri = request.getURI();
|
||||
|
||||
String scheme=uri.getScheme();
|
||||
if (scheme!=null)
|
||||
setScheme(scheme);
|
||||
|
||||
String uriHost=uri.getHost();
|
||||
if (uriHost!=null)
|
||||
{
|
||||
// Give precidence to authority in absolute URI
|
||||
setServerName(uriHost);
|
||||
setServerPort(uri.getPort());
|
||||
}
|
||||
|
||||
setUri(uri);
|
||||
|
||||
|
||||
String path = uri.getDecodedPath();
|
||||
String info;
|
||||
if (path==null || path.length()==0)
|
||||
{
|
||||
if (uri.isAbsolute())
|
||||
{
|
||||
path="/";
|
||||
uri.setPath(path);
|
||||
}
|
||||
else
|
||||
throw new BadMessageException(400,"Bad URI");
|
||||
info=path;
|
||||
}
|
||||
else if (!path.startsWith("/"))
|
||||
{
|
||||
System.err.println(request);
|
||||
if (!"*".equals(path) && !HttpMethod.CONNECT.is(getMethod()))
|
||||
throw new BadMessageException(400,"Bad URI");
|
||||
info=path;
|
||||
|
@ -1619,23 +1645,16 @@ public class Request implements HttpServletRequest
|
|||
_cookiesExtracted = false;
|
||||
_context = null;
|
||||
_newContext=false;
|
||||
_serverName = null;
|
||||
_httpMethod = null;
|
||||
_pathInfo = null;
|
||||
_serverPort = 0;
|
||||
_queryEncoding = null;
|
||||
_queryString = null;
|
||||
_requestedSessionId = null;
|
||||
_requestedSessionIdFromCookie = false;
|
||||
_secure=false;
|
||||
_session = null;
|
||||
_sessionManager = null;
|
||||
_requestURI = null;
|
||||
_scope = null;
|
||||
_scheme = URIUtil.HTTP;
|
||||
_servletPath = null;
|
||||
_timeStamp = 0;
|
||||
_uri = null;
|
||||
_queryParameters = null;
|
||||
_contentParameters = null;
|
||||
_parameters = null;
|
||||
|
@ -1859,13 +1878,13 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public void setMethod(String method)
|
||||
{
|
||||
_httpMethod = method;
|
||||
_metadata.setMethod(method);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isHead()
|
||||
{
|
||||
return HttpMethod.HEAD.asString().equals(_httpMethod);
|
||||
return _metadata!=null && HttpMethod.HEAD.is(_metadata.getMethod());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1890,7 +1909,6 @@ public class Request implements HttpServletRequest
|
|||
public void setQueryEncoding(String queryEncoding)
|
||||
{
|
||||
_queryEncoding = queryEncoding;
|
||||
_queryString = null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1900,7 +1918,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public void setQueryString(String queryString)
|
||||
{
|
||||
_queryString = queryString;
|
||||
_metadata.getURI().setQuery(queryString);
|
||||
_queryEncoding = null; //assume utf-8
|
||||
}
|
||||
|
||||
|
@ -1935,13 +1953,9 @@ public class Request implements HttpServletRequest
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param requestURI
|
||||
* The requestURI to set.
|
||||
*/
|
||||
public void setRequestURI(String requestURI)
|
||||
public void setURIPathQuery(String requestURI)
|
||||
{
|
||||
_requestURI = requestURI;
|
||||
_metadata.getURI().setPathQuery(requestURI);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1951,7 +1965,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public void setScheme(String scheme)
|
||||
{
|
||||
_scheme = scheme;
|
||||
_metadata.getURI().setScheme(scheme);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1959,19 +1973,9 @@ public class Request implements HttpServletRequest
|
|||
* @param host
|
||||
* The host to set.
|
||||
*/
|
||||
public void setServerName(String host)
|
||||
public void setAuthority(String host,int port)
|
||||
{
|
||||
_serverName = host;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param port
|
||||
* The port to set.
|
||||
*/
|
||||
public void setServerPort(int port)
|
||||
{
|
||||
_serverPort = port;
|
||||
_metadata.getURI().setAuthority(host,port);;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -2010,16 +2014,6 @@ public class Request implements HttpServletRequest
|
|||
_timeStamp = ts;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param uri
|
||||
* The uri to set.
|
||||
*/
|
||||
public void setUri(HttpURI uri)
|
||||
{
|
||||
_uri = uri;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setUserIdentityScope(UserIdentity.Scope scope)
|
||||
{
|
||||
|
@ -2060,7 +2054,7 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return (_handled?"[":"(") + getMethod() + " " + _uri + (_handled?"]@":")@") + hashCode() + " " + super.toString();
|
||||
return (_handled?"[":"(") + getMethod() + " " + _metadata.getURI() + (_handled?"]@":")@") + hashCode() + " " + super.toString();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -2174,10 +2168,10 @@ public class Request implements HttpServletRequest
|
|||
UrlEncoded.decodeTo(newQuery, newQueryParams, UrlEncoded.ENCODING);
|
||||
|
||||
MultiMap<String> oldQueryParams = _queryParameters;
|
||||
if (oldQueryParams == null && _queryString != null)
|
||||
if (oldQueryParams == null && getQueryString() != null)
|
||||
{
|
||||
oldQueryParams = new MultiMap<>();
|
||||
UrlEncoded.decodeTo(_queryString, oldQueryParams, getQueryEncoding());
|
||||
UrlEncoded.decodeTo(getQueryString(), oldQueryParams, getQueryEncoding());
|
||||
}
|
||||
|
||||
MultiMap<String> mergedQueryParams = newQueryParams;
|
||||
|
|
|
@ -440,9 +440,13 @@ public class Response implements HttpServletResponse
|
|||
int port = uri.getPort();
|
||||
if (port < 0)
|
||||
port = HttpScheme.HTTPS.asString().equalsIgnoreCase(uri.getScheme()) ? 443 : 80;
|
||||
if (!request.getServerName().equalsIgnoreCase(uri.getHost()) ||
|
||||
request.getServerPort() != port ||
|
||||
!path.startsWith(request.getContextPath())) //TODO the root context path is "", with which every non null string starts
|
||||
|
||||
// Is it the same server?
|
||||
if (!request.getServerName().equalsIgnoreCase(uri.getHost()))
|
||||
return url;
|
||||
if (request.getServerPort() != port)
|
||||
return url;
|
||||
if (!path.startsWith(request.getContextPath())) //TODO the root context path is "", with which every non null string starts
|
||||
return url;
|
||||
}
|
||||
|
||||
|
|
|
@ -519,9 +519,8 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
{
|
||||
// this is a dispatch with a path
|
||||
ServletContext context=event.getServletContext();
|
||||
HttpURI uri = new HttpURI(URIUtil.addPaths(context==null?null:context.getContextPath(), path));
|
||||
baseRequest.setUri(uri);
|
||||
baseRequest.setRequestURI(null);
|
||||
baseRequest.setURIPathQuery(URIUtil.addPaths(context==null?null:context.getContextPath(), path));
|
||||
HttpURI uri = baseRequest.getUri();
|
||||
baseRequest.setPathInfo(uri.getDecodedPath());
|
||||
if (uri.getQuery()!=null)
|
||||
baseRequest.mergeQueryParameters(uri.getQuery(), true); //we have to assume dispatch path and query are UTF8
|
||||
|
|
|
@ -47,6 +47,8 @@ import org.eclipse.jetty.http.HttpFields;
|
|||
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http.MetaData;
|
||||
import org.eclipse.jetty.io.AbstractEndPoint;
|
||||
import org.eclipse.jetty.io.ByteArrayEndPoint;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
|
@ -415,8 +417,7 @@ public class ResponseTest
|
|||
{
|
||||
Response response = newResponse();
|
||||
Request request = response.getHttpChannel().getRequest();
|
||||
request.setServerName("myhost");
|
||||
request.setServerPort(8888);
|
||||
request.setAuthority("myhost",8888);
|
||||
request.setContextPath("/path");
|
||||
|
||||
assertEquals("http://myhost:8888/path/info;param?query=0&more=1#target", response.encodeURL("http://myhost:8888/path/info;param?query=0&more=1#target"));
|
||||
|
@ -491,9 +492,8 @@ public class ResponseTest
|
|||
Response response = newResponse();
|
||||
Request request = response.getHttpChannel().getRequest();
|
||||
|
||||
request.setServerName(host);
|
||||
request.setServerPort(port);
|
||||
request.setUri(new HttpURI("/path/info;param;jsessionid=12345?query=0&more=1#target"));
|
||||
request.setAuthority(host,port);
|
||||
request.setURIPathQuery("/path/info;param;jsessionid=12345?query=0&more=1#target");
|
||||
request.setContextPath("/path");
|
||||
request.setRequestedSessionId("12345");
|
||||
request.setRequestedSessionIdFromCookie(i>2);
|
||||
|
@ -657,7 +657,7 @@ public class ResponseTest
|
|||
@Test
|
||||
public void testFlushAfterFullContent() throws Exception
|
||||
{
|
||||
Response response = _channel.getResponse();
|
||||
Response response = newResponse();
|
||||
byte[] data = new byte[]{(byte)0xCA, (byte)0xFE};
|
||||
ServletOutputStream output = response.getOutputStream();
|
||||
response.setContentLength(data.length);
|
||||
|
@ -790,6 +790,7 @@ public class ResponseTest
|
|||
private Response newResponse()
|
||||
{
|
||||
_channel.reset();
|
||||
_channel.getRequest().setMetaData(new MetaData.Request("GET",new HttpURI("/path/info"),HttpVersion.HTTP_1_0,new HttpFields()));
|
||||
return new Response(_channel, _channel.getResponse().getHttpOutput());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.eclipse.jetty.http.HostPortHttpField;
|
|||
import org.eclipse.jetty.http.HttpField;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpScheme;
|
||||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http.MetaData;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
|
@ -107,9 +107,6 @@ public class HttpChannelOverSPDY extends HttpChannel
|
|||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("HTTP > {} {} {}", httpMethod, uriHeader.getValue(), httpVersion);
|
||||
|
||||
Fields.Field schemeHeader = headers.get(HTTPSPDYHeader.SCHEME.name(version));
|
||||
if (schemeHeader != null)
|
||||
getRequest().setScheme(schemeHeader.getValue());
|
||||
|
||||
HostPortHttpField hostPort = null;
|
||||
HttpFields fields = new HttpFields();
|
||||
|
@ -160,9 +157,18 @@ public class HttpChannelOverSPDY extends HttpChannel
|
|||
}
|
||||
|
||||
// At last, add the Host header.
|
||||
fields.add(hostPort);
|
||||
if (hostPort!=null)
|
||||
fields.add(hostPort);
|
||||
|
||||
MetaData.Request request = new MetaData.Request(httpMethod==null?methodHeader.getValue():httpMethod.asString(), HttpScheme.HTTP.asString(), hostPort, uriHeader.getValue(), httpVersion, fields);
|
||||
Fields.Field schemeHeader = headers.get(HTTPSPDYHeader.SCHEME.name(version));
|
||||
|
||||
HttpURI uri = new HttpURI(uriHeader.getValue());
|
||||
if (uri.getScheme()==null && schemeHeader!=null)
|
||||
uri.setScheme(schemeHeader.getValue());
|
||||
if (uri.getHost()==null && hostPort!=null)
|
||||
uri.setAuthority(hostPort.getHost(),hostPort.getPort());
|
||||
|
||||
MetaData.Request request = new MetaData.Request(httpMethod==null?methodHeader.getValue():httpMethod.asString(), uri, httpVersion, fields);
|
||||
onRequest(request);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.webapp;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -32,8 +33,6 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.server.LocalConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
|
@ -41,6 +40,7 @@ import org.eclipse.jetty.server.handler.HandlerList;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceCollection;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WebAppContextTest
|
||||
|
@ -51,7 +51,7 @@ public class WebAppContextTest
|
|||
Server server = new Server();
|
||||
//test if no classnames set, its the defaults
|
||||
WebAppContext wac = new WebAppContext();
|
||||
Assert.assertEquals(0,wac.getConfigurations().length);
|
||||
assertEquals(0,wac.getConfigurations().length);
|
||||
String[] classNames = wac.getConfigurationClasses();
|
||||
assertNotNull(classNames);
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ public class TestableJettyServer
|
|||
for (int i = 0; i < this._xmlConfigurations.size(); i++)
|
||||
{
|
||||
URL configURL = this._xmlConfigurations.get(i);
|
||||
System.err.println("configuring: "+configURL);
|
||||
// System.err.println("configuring: "+configURL);
|
||||
XmlConfiguration configuration = new XmlConfiguration(configURL);
|
||||
if (last != null)
|
||||
{
|
||||
|
@ -177,8 +177,8 @@ public class TestableJettyServer
|
|||
_server.start();
|
||||
|
||||
// Find the active server port.
|
||||
this._serverPort = ((NetworkConnector)_server.getConnectors()[0]).getPort();
|
||||
System.err.println("Server Port="+_serverPort);
|
||||
this._serverPort = ((NetworkConnector)_server.getConnectors()[0]).getLocalPort();
|
||||
// System.err.println("Server Port="+_serverPort);
|
||||
Assert.assertTrue("Server Port is between 1 and 65535. Actually <" + _serverPort + ">",(1 <= this._serverPort) && (this._serverPort <= 65535));
|
||||
}
|
||||
|
||||
|
|
|
@ -104,21 +104,21 @@ public class HttpResponseTesterTest
|
|||
Assert.assertEquals("Responses.size",3,responses.size());
|
||||
|
||||
HttpTester.Response resp1 = responses.get(0);
|
||||
System.err.println(resp1.toString());
|
||||
// System.err.println(resp1.toString());
|
||||
Assert.assertEquals(HttpStatus.OK_200, resp1.getStatus());
|
||||
Assert.assertEquals("text/plain", resp1.get("Content-Type"));
|
||||
Assert.assertTrue(resp1.getContent().contains("ABCDEFGHIJKLMNOPQRSTTUVWXYZ\n"));
|
||||
assertThat(resp1.get("Connection"),is(not("close")));
|
||||
|
||||
HttpTester.Response resp2 = responses.get(1);
|
||||
System.err.println(resp2.toString());
|
||||
// System.err.println(resp2.toString());
|
||||
Assert.assertEquals(HttpStatus.OK_200, resp2.getStatus());
|
||||
Assert.assertEquals("text/plain", resp2.get("Content-Type"));
|
||||
Assert.assertTrue(resp2.getContent().contains("Host=Default\nResource=R1\n"));
|
||||
assertThat(resp2.get("Connection"),is(not("close")));
|
||||
|
||||
HttpTester.Response resp3 = responses.get(2);
|
||||
System.err.println(resp3.toString());
|
||||
// System.err.println(resp3.toString());
|
||||
Assert.assertEquals(HttpStatus.OK_200, resp3.getStatus());
|
||||
Assert.assertEquals("text/plain", resp3.get("Content-Type"));
|
||||
Assert.assertTrue(resp3.getContent().contains("Host=Default\nResource=R2\n"));
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.bio.SocketConnector">
|
||||
<Set name="host"><SystemProperty name="jetty.host" /></Set>
|
||||
<Set name="port"><SystemProperty name="jetty.port" default="0"/></Set>
|
||||
<Set name="idleTimeout">300000</Set>
|
||||
<Set name="Acceptors">2</Set>
|
||||
<Set name="statsOn">false</Set>
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ssl.SslSocketConnector">
|
||||
<Set name="host"><SystemProperty name="jetty.host" /></Set>
|
||||
<Set name="port"><SystemProperty name="jetty.port" default="0"/></Set>
|
||||
<Set name="idleTimeout">300000</Set>
|
||||
<Set name="Acceptors">2</Set>
|
||||
<Set name="statsOn">false</Set>
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
</Array>
|
||||
</Arg>
|
||||
<Set name="host"><Property name="jetty.host" /></Set>
|
||||
<Set name="port"><Property name="jetty.port" default="8080" /></Set>
|
||||
<Set name="idleTimeout"><Property name="http.timeout" default="30000"/></Set>
|
||||
</New>
|
||||
</Arg>
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
</Array>
|
||||
</Arg>
|
||||
<Set name="host"><Property name="jetty.host" /></Set>
|
||||
<Set name="port"><Property name="jetty.https.port" default="8443" /></Set>
|
||||
<Set name="idleTimeout">30000</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
|
|
Loading…
Reference in New Issue