[Bug 358925] adjust some code and add license block

This commit is contained in:
Jesse McConnell 2011-09-26 17:22:08 -05:00
parent e14cc536ee
commit bee0a6e777
2 changed files with 51 additions and 20 deletions

View File

@ -1,5 +1,18 @@
package org.eclipse.jetty.rewrite.handler; package org.eclipse.jetty.rewrite.handler;
//========================================================================
//Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//All rights reserved. This program and the accompanying materials
//are made available under the terms of the Eclipse Public License v1.0
//and Apache License v2.0 which accompanies this distribution.
//The Eclipse Public License is available at
//http://www.eclipse.org/legal/epl-v10.html
//The Apache License v2.0 is available at
//http://www.opensource.org/licenses/apache2.0.php
//You may elect to redistribute this code under either of these licenses.
//========================================================================
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -48,7 +61,6 @@ public class ProxyRule extends PatternRule
{ {
_handling = true; _handling = true;
_terminating = true; _terminating = true;
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -201,20 +213,25 @@ public class ProxyRule extends PatternRule
exchange.setVersion(request.getProtocol()); exchange.setVersion(request.getProtocol());
if (debug != 0) if (debug != 0)
{
_log.debug(debug + " " + request.getMethod() + " " + url + " " + request.getProtocol()); _log.debug(debug + " " + request.getMethod() + " " + url + " " + request.getProtocol());
}
boolean hasContent = createHeaders(request,debug,exchange); boolean hasContent = createHeaders(request,debug,exchange);
if (hasContent) if (hasContent)
{
exchange.setRequestContentSource(in); exchange.setRequestContentSource(in);
}
/* /*
* we need to set the timeout on the continuation to take into account the timeout of the HttpClient and the HttpExchange * we need to set the timeout on the exchange to take into account the timeout of the HttpClient and the HttpExchange
*/ */
long ctimeout = (_client.getTimeout() > exchange.getTimeout())?_client.getTimeout():exchange.getTimeout(); long ctimeout = (_client.getTimeout() > exchange.getTimeout())?_client.getTimeout():exchange.getTimeout();
exchange.setTimeout(ctimeout); exchange.setTimeout(ctimeout);
_client.send(exchange); _client.send(exchange);
try try
{ {
exchange.waitForDone(); exchange.waitForDone();
@ -230,15 +247,26 @@ public class ProxyRule extends PatternRule
private HttpURI createUrl(HttpServletRequest request, final int debug) throws MalformedURLException private HttpURI createUrl(HttpServletRequest request, final int debug) throws MalformedURLException
{ {
String uri = request.getRequestURI(); String uri = request.getRequestURI();
if (request.getQueryString() != null) if (request.getQueryString() != null)
{
uri += "?" + request.getQueryString(); uri += "?" + request.getQueryString();
}
uri = PathMap.pathInfo(_pattern,uri); uri = PathMap.pathInfo(_pattern,uri);
if(uri==null) if(uri==null)
{
uri = "/"; uri = "/";
}
HttpURI url = proxyHttpURI(uri); HttpURI url = proxyHttpURI(uri);
if (debug != 0) if (debug != 0)
{
_log.debug(debug + " proxy " + uri + "-->" + url); _log.debug(debug + " proxy " + uri + "-->" + url);
}
return url; return url;
} }
@ -251,12 +279,16 @@ public class ProxyRule extends PatternRule
{ {
connectionHdr = connectionHdr.toLowerCase(); connectionHdr = connectionHdr.toLowerCase();
if (connectionHdr.indexOf("keep-alive") < 0 && connectionHdr.indexOf("close") < 0) if (connectionHdr.indexOf("keep-alive") < 0 && connectionHdr.indexOf("close") < 0)
{
connectionHdr = null; connectionHdr = null;
}
} }
// force host // force host
if (_hostHeader != null) if (_hostHeader != null)
{
exchange.setRequestHeader("Host",_hostHeader); exchange.setRequestHeader("Host",_hostHeader);
}
// copy headers // copy headers
boolean xForwardedFor = false; boolean xForwardedFor = false;

View File

@ -1,17 +1,18 @@
// ========================================================================
// Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.rewrite.handler; package org.eclipse.jetty.rewrite.handler;
//========================================================================
//Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//All rights reserved. This program and the accompanying materials
//are made available under the terms of the Eclipse Public License v1.0
//and Apache License v2.0 which accompanies this distribution.
//The Eclipse Public License is available at
//http://www.eclipse.org/legal/epl-v10.html
//The Apache License v2.0 is available at
//http://www.opensource.org/licenses/apache2.0.php
//You may elect to redistribute this code under either of these licenses.
//========================================================================
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
@ -50,8 +51,7 @@ public class ProxyRuleTest
_targetServer.addConnector(_targetServerConnector); _targetServer.addConnector(_targetServerConnector);
_targetServer.setHandler(new AbstractHandler() _targetServer.setHandler(new AbstractHandler()
{ {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
ServletException
{ {
baseRequest.setHandled(true); baseRequest.setHandled(true);
String responseString = "uri: " + request.getRequestURI() + " some content"; String responseString = "uri: " + request.getRequestURI() + " some content";
@ -66,8 +66,7 @@ public class ProxyRuleTest
_rule.setProxyTo("http://localhost:" + _targetServerConnector.getLocalPort()); _rule.setProxyTo("http://localhost:" + _targetServerConnector.getLocalPort());
_handler = new RewriteHandler(); _handler = new RewriteHandler();
_handler.setRewriteRequestURI(true); _handler.setRewriteRequestURI(true);
_handler.setRules(new Rule[] _handler.setRules(new Rule[] { _rule });
{ _rule });
_proxyServer.addConnector(_proxyServerConnector); _proxyServer.addConnector(_proxyServerConnector);
_proxyServer.setHandler(_handler); _proxyServer.setHandler(_handler);