Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpStatus.java1
-rw-r--r--jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java2
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/Request.java3
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/Response.java6
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java46
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java13
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java29
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java21
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilTest.java (renamed from jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java)26
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java42
10 files changed, 142 insertions, 47 deletions
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpStatus.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpStatus.java
index e6ea1f714a..7db1fa64ff 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpStatus.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpStatus.java
@@ -612,7 +612,6 @@ package org.eclipse.jetty.http;
*/
public class HttpStatus
{
- public final static int NOT_SET_000 = 0;
public final static int CONTINUE_100 = 100;
public final static int SWITCHING_PROTOCOLS_101 = 101;
public final static int PROCESSING_102 = 102;
diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java
index 47fa517d9b..e8d6cda940 100644
--- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java
+++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java
@@ -45,7 +45,7 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
_rule.matchAndApply(_request.getRequestURI(), _request, _response);
- assertEquals(0,_response.getStatus());
+ assertEquals(200,_response.getStatus());
}
@Test
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
index d442216814..fc1d6dcdbc 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
@@ -1790,9 +1790,6 @@ public class Request implements HttpServletRequest
public void setHandled(boolean h)
{
_handled = h;
- Response r=getResponse();
- if (_handled && r.getStatus()==0)
- r.setStatus(200);
}
/* ------------------------------------------------------------ */
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
index 3b8d2aab42..987694724e 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
@@ -112,7 +112,7 @@ public class Response implements HttpServletResponse
private final HttpFields _fields = new HttpFields();
private final AtomicInteger _include = new AtomicInteger();
private HttpOutput _out;
- private int _status = HttpStatus.NOT_SET_000;
+ private int _status = HttpStatus.OK_200;
private String _reason;
private Locale _locale;
private MimeTypes.Type _mimeType;
@@ -137,7 +137,7 @@ public class Response implements HttpServletResponse
protected void recycle()
{
- _status = HttpStatus.NOT_SET_000;
+ _status = HttpStatus.OK_200;
_reason = null;
_locale = null;
_mimeType = null;
@@ -1290,8 +1290,6 @@ public class Response implements HttpServletResponse
protected ResponseInfo newResponseInfo()
{
- if (_status == HttpStatus.NOT_SET_000)
- _status = HttpStatus.OK_200;
return new ResponseInfo(_channel.getRequest().getHttpVersion(), _fields, getLongContentLength(), getStatus(), getReason(), _channel.getRequest().isHead());
}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java
index 98bb413429..2e4ec6b745 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java
@@ -193,35 +193,35 @@ public class StatisticsHandler extends HandlerWrapper implements Graceful
}
}
- private void updateResponse(Request request)
+ protected void updateResponse(Request request)
{
Response response = request.getResponse();
- switch (response.getStatus() / 100)
+ if (request.isHandled())
{
- case 0:
- if (request.isHandled())
+ switch (response.getStatus() / 100)
+ {
+ case 1:
+ _responses1xx.incrementAndGet();
+ break;
+ case 2:
_responses2xx.incrementAndGet();
- else
+ break;
+ case 3:
+ _responses3xx.incrementAndGet();
+ break;
+ case 4:
_responses4xx.incrementAndGet();
- break;
- case 1:
- _responses1xx.incrementAndGet();
- break;
- case 2:
- _responses2xx.incrementAndGet();
- break;
- case 3:
- _responses3xx.incrementAndGet();
- break;
- case 4:
- _responses4xx.incrementAndGet();
- break;
- case 5:
- _responses5xx.incrementAndGet();
- break;
- default:
- break;
+ break;
+ case 5:
+ _responses5xx.incrementAndGet();
+ break;
+ default:
+ break;
+ }
}
+ else
+ // will fall through to not found handler
+ _responses4xx.incrementAndGet();
_responsesTotalBytes.addAndGet(response.getContentCount());
}
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java
index 2317195a18..965dd18de4 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java
@@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
@@ -191,11 +192,21 @@ public class ServletTester extends ContainerLifeCycle
{
return _connector.getResponses(request);
}
-
+
+ public String getResponses(String request, long idleFor,TimeUnit units) throws Exception
+ {
+ return _connector.getResponses(request, idleFor, units);
+ }
+
public ByteBuffer getResponses(ByteBuffer request) throws Exception
{
return _connector.getResponses(request);
}
+
+ public ByteBuffer getResponses(ByteBuffer requestsBuffer,long idleFor,TimeUnit units) throws Exception
+ {
+ return _connector.getResponses(requestsBuffer, idleFor, units);
+ }
/* ------------------------------------------------------------ */
/** Create a port based connector.
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java
index f333fc3b5f..703ca0d017 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java
@@ -688,6 +688,35 @@ public class URIUtil
url.append(':').append(port);
}
}
+
+ public static boolean equalsIgnoreEncodings(String uriA, String uriB)
+ {
+ int lenA=uriA.length();
+ int lenB=uriB.length();
+ int a=0;
+ int b=0;
+
+ while (a<lenA && b<lenB)
+ {
+ int oa=uriA.charAt(a++);
+ int ca=oa;
+ if (ca=='%')
+ ca=TypeUtil.convertHexDigit(uriA.charAt(a++))*16+TypeUtil.convertHexDigit(uriA.charAt(a++));
+
+ int ob=uriB.charAt(b++);
+ int cb=ob;
+ if (cb=='%')
+ cb=TypeUtil.convertHexDigit(uriB.charAt(b++))*16+TypeUtil.convertHexDigit(uriB.charAt(b++));
+
+ if (ca!=cb)
+ return false;
+
+ if (ca=='/' && oa!=ob)
+ return false;
+ }
+
+ return a==lenA && b==lenB;
+ }
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java
index 449884241b..7175a9c3d7 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java
@@ -98,7 +98,7 @@ public class FileResource extends Resource
_file=file;
_uri=normalizeURI(_file,url.toURI());
- _alias=checkAlias(_file);
+ _alias=checkFileAlias(_file);
}
/* -------------------------------------------------------- */
@@ -108,17 +108,12 @@ public class FileResource extends Resource
_file=file;
URI file_uri=_file.toURI();
_uri=normalizeURI(_file,uri);
-
- if (!_uri.equals(file_uri.toString()))
- {
- // URI and File URI are different. Is it just an encoding difference?
- if (!file_uri.toString().equals(URIUtil.decodePath(uri.toString())))
- _alias=_file.toURI();
- else
- _alias=checkAlias(_file);
- }
+
+ // Is it a URI alias?
+ if (!URIUtil.equalsIgnoreEncodings(_uri,file_uri.toString()))
+ _alias=_file.toURI();
else
- _alias=checkAlias(_file);
+ _alias=checkFileAlias(_file);
}
/* -------------------------------------------------------- */
@@ -126,7 +121,7 @@ public class FileResource extends Resource
{
_file=file;
_uri=normalizeURI(_file,_file.toURI());
- _alias=checkAlias(_file);
+ _alias=checkFileAlias(_file);
}
/* -------------------------------------------------------- */
@@ -144,7 +139,7 @@ public class FileResource extends Resource
}
/* -------------------------------------------------------- */
- private static URI checkAlias(File file)
+ private static URI checkFileAlias(File file)
{
try
{
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilTest.java
index 9ab2bd27e7..9165b35a20 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilTest.java
@@ -19,9 +19,12 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.nio.charset.StandardCharsets;
+import org.junit.Assert;
import org.junit.Test;
@@ -29,7 +32,7 @@ import org.junit.Test;
/** Util meta Tests.
*
*/
-public class URITest
+public class URIUtilTest
{
/* ------------------------------------------------------------ */
@Test
@@ -185,6 +188,27 @@ public class URITest
assertEquals("parent null",null, URIUtil.parentPath(null));
}
+ /* ------------------------------------------------------------ */
+ @Test
+ public void testEqualsIgnoreEncoding()
+ {
+ assertTrue(URIUtil.equalsIgnoreEncodings("http://example.com/foo/bar","http://example.com/foo/bar" ));
+ assertTrue(URIUtil.equalsIgnoreEncodings("/barry's","/barry%27s"));
+ assertTrue(URIUtil.equalsIgnoreEncodings("/barry%27s","/barry's"));
+ assertTrue(URIUtil.equalsIgnoreEncodings("/barry%27s","/barry%27s"));
+ assertTrue(URIUtil.equalsIgnoreEncodings("/b rry's","/b%20rry%27s"));
+ assertTrue(URIUtil.equalsIgnoreEncodings("/b rry%27s","/b%20rry's"));
+ assertTrue(URIUtil.equalsIgnoreEncodings("/b rry%27s","/b%20rry%27s"));
+
+ assertTrue(URIUtil.equalsIgnoreEncodings("/foo%2fbar","/foo%2fbar"));
+ assertTrue(URIUtil.equalsIgnoreEncodings("/foo%2fbar","/foo%2Fbar"));
+
+ assertFalse(URIUtil.equalsIgnoreEncodings("ABC", "abc"));
+ assertFalse(URIUtil.equalsIgnoreEncodings("/barry's","/barry%26s"));
+
+ assertFalse(URIUtil.equalsIgnoreEncodings("/foo/bar","/foo%2fbar"));
+ assertFalse(URIUtil.equalsIgnoreEncodings("/foo2fbar","/foo/bar"));
+ }
/* ------------------------------------------------------------ */
@Test
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java
index 2b4659ea6f..e77f241b49 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java
@@ -32,6 +32,7 @@ import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.toolchain.test.OS;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.util.UrlEncoded;
+import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Rule;
@@ -81,6 +82,47 @@ public class FileResourceTest
}
}
+ @Test
+ public void testSingleQuoteInFileName() throws Exception
+ {
+ createDummyFile("foo's.txt");
+ createDummyFile("f o's.txt");
+
+ URI refQuoted = testdir.getDir().toURI().resolve("foo's.txt");
+
+ try(FileResource fileres = new FileResource(refQuoted))
+ {
+ Assert.assertThat(fileres.exists(),is(true));
+ Assert.assertThat(fileres.getAlias(),Matchers.nullValue());
+ }
+
+ URI refEncoded = testdir.getDir().toURI().resolve("foo%27s.txt");
+
+ try(FileResource fileres = new FileResource(refEncoded))
+ {
+ Assert.assertThat(fileres.exists(),is(true));
+ Assert.assertThat(fileres.getAlias(),Matchers.nullValue());
+ }
+
+ URI refQuoteSpace = testdir.getDir().toURI().resolve("f%20o's.txt");
+
+ try(FileResource fileres = new FileResource(refQuoteSpace))
+ {
+ Assert.assertThat(fileres.exists(),is(true));
+ Assert.assertThat(fileres.getAlias(),Matchers.nullValue());
+ }
+
+ URI refEncodedSpace = testdir.getDir().toURI().resolve("f%20o%27s.txt");
+
+ try(FileResource fileres = new FileResource(refEncodedSpace))
+ {
+ Assert.assertThat(fileres.exists(),is(true));
+ Assert.assertThat(fileres.getAlias(),Matchers.nullValue());
+ }
+ }
+
+
+
@Ignore("Cannot get null to be seen by FileResource")
@Test
public void testExist_BadNull() throws Exception

Back to the top