Issue #1103 original URI trimmed

This commit is contained in:
Greg Wilkins 2016-11-16 23:31:03 +11:00
parent e1916ab83d
commit ed14d739f3
6 changed files with 73 additions and 54 deletions

View File

@ -42,6 +42,7 @@ public class DumpServlet extends HttpServlet
out.println("<h1>DumpServlet</h1>");
out.println("<pre>");
out.println("requestURI=" + request.getRequestURI());
out.println("requestURL=" + request.getRequestURL().toString());
out.println("contextPath=" + request.getContextPath());
out.println("servletPath=" + request.getServletPath());
out.println("pathInfo=" + request.getPathInfo());

View File

@ -39,10 +39,6 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<!--
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
-->
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
@ -83,5 +79,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</dependencies>
</project>

View File

@ -24,7 +24,7 @@ import java.util.Locale;
import javax.servlet.http.Cookie;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.PathMap;
import org.eclipse.jetty.http.pathmap.PathMappings;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.util.DateCache;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
@ -54,7 +54,7 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement
private String[] _ignorePaths;
private boolean _extended;
private transient PathMap<String> _ignorePathMap;
private transient PathMappings<String> _ignorePathMap;
private boolean _logLatency = false;
private boolean _logCookies = false;
private boolean _logServer = false;
@ -222,13 +222,14 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement
}
/**
* @param request request object
* @param b StringBuilder to write to
* @throws IOException if unable to append extended log
* @deprecated override {@link #logExtended(StringBuilder, Request, Response)} instead
* Writes extended request and response information to the output stream.
*
* @param b StringBuilder to write to
* @param request request object
* @param response response object
* @throws IOException if unable to log the extended information
*/
@Deprecated
protected void logExtended(Request request, StringBuilder b) throws IOException
protected void logExtended(StringBuilder b, Request request, Response response) throws IOException
{
String referer = request.getHeader(HttpHeader.REFERER.toString());
if (referer == null)
@ -251,19 +252,6 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement
}
}
/**
* Writes extended request and response information to the output stream.
*
* @param b StringBuilder to write to
* @param request request object
* @param response response object
* @throws IOException if unable to log the extended information
*/
protected void logExtended(StringBuilder b, Request request, Response response) throws IOException
{
logExtended(request, b);
}
/**
* Set request paths that will not be logged.
*
@ -423,7 +411,7 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement
if (_ignorePaths != null && _ignorePaths.length > 0)
{
_ignorePathMap = new PathMap<>();
_ignorePathMap = new PathMappings<>();
for (int i = 0; i < _ignorePaths.length; i++)
_ignorePathMap.put(_ignorePaths[i], _ignorePaths[i]);
}

View File

@ -1734,9 +1734,10 @@ public class Request implements HttpServletRequest
public void setMetaData(org.eclipse.jetty.http.MetaData.Request request)
{
_metaData=request;
_originalURI=_metaData.getURIString();
setMethod(request.getMethod());
HttpURI uri = request.getURI();
_originalURI=uri.isAbsolute()&&request.getHttpVersion()!=HttpVersion.HTTP_2?uri.toString():uri.getPathQuery();
String path = uri.getDecodedPath();
String info;

View File

@ -80,9 +80,7 @@ public class RequestLogTest
{
_connector.getResponse("GET /foo?data=1 HTTP/1.0\nhost: host:80\n\n");
String log = _log.exchange(null,5,TimeUnit.SECONDS);
// TODO should be without host (https://bugs.eclipse.org/bugs/show_bug.cgi?id=480276)
// assertThat(log,containsString("GET /foo?data=1 HTTP/1.0\" 200 "));
assertThat(log,containsString("GET //host:80/foo?data=1 HTTP/1.0\" 200 "));
assertThat(log,containsString("GET /foo?data=1 HTTP/1.0\" 200 "));
_connector.getResponse("GET //bad/foo?data=1 HTTP/1.0\n\n");
log = _log.exchange(null,5,TimeUnit.SECONDS);
@ -93,6 +91,51 @@ public class RequestLogTest
assertThat(log,containsString("GET http://host:80/foo?data=1 HTTP/1.0\" 200 "));
}
@Test
public void testHTTP10Host() throws Exception
{
_connector.getResponse(
"GET /foo?name=value HTTP/1.0\n"+
"Host: servername\n"+
"\n");
String log = _log.exchange(null,5,TimeUnit.SECONDS);
assertThat(log,containsString("GET /foo?name=value"));
assertThat(log,containsString(" 200 "));
}
@Test
public void testHTTP11() throws Exception
{
_connector.getResponse(
"GET /foo?name=value HTTP/1.1\n"+
"Host: servername\n"+
"\n");
String log = _log.exchange(null,5,TimeUnit.SECONDS);
assertThat(log,containsString("GET /foo?name=value"));
assertThat(log,containsString(" 200 "));
}
@Test
public void testAbsolute() throws Exception
{
_connector.getResponse(
"GET http://hostname:8888/foo?name=value HTTP/1.1\n"+
"Host: servername\n"+
"\n");
String log = _log.exchange(null,5,TimeUnit.SECONDS);
assertThat(log,containsString("GET http://hostname:8888/foo?name=value"));
assertThat(log,containsString(" 200 "));
}
@Test
public void testQuery() throws Exception
{
_connector.getResponse("GET /foo?name=value HTTP/1.0\n\n");
String log = _log.exchange(null,5,TimeUnit.SECONDS);
assertThat(log,containsString("GET /foo?name=value"));
assertThat(log,containsString(" 200 "));
}
@Test
public void testSmallData() throws Exception
{

View File

@ -33,6 +33,7 @@ import java.net.URL;
import java.net.UnknownHostException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@ -1429,13 +1430,12 @@ public class XmlConfiguration
*/
public static void main(final String... args) throws Exception
{
final AtomicReference<Throwable> exception = new AtomicReference<>();
AccessController.doPrivileged(new PrivilegedAction<Object>()
try
{
public Object run()
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
{
try
@Override
public Void run() throws Exception
{
Properties properties = null;
@ -1509,26 +1509,15 @@ public class XmlConfiguration
lc.start();
}
}
}
catch (Exception e)
{
LOG.debug(Log.EXCEPTION,e);
exception.set(e);
}
return null;
}
});
Throwable th = exception.get();
if (th != null)
return null;
}
});
}
catch (Error|Exception e)
{
if (th instanceof RuntimeException)
throw (RuntimeException)th;
else if (th instanceof Exception)
throw (Exception)th;
else if (th instanceof Error)
throw (Error)th;
throw new Error(th);
LOG.warn(e);
throw e;
}
}
}