Merge remote-tracking branch 'origin/master' into jetty-http2

This commit is contained in:
Greg Wilkins 2014-06-24 17:33:51 +02:00
commit f93a409589
10 changed files with 142 additions and 47 deletions

View File

@ -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;

View File

@ -45,7 +45,7 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
_rule.matchAndApply(_request.getRequestURI(), _request, _response);
assertEquals(0,_response.getStatus());
assertEquals(200,_response.getStatus());
}
@Test

View File

@ -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);
}
/* ------------------------------------------------------------ */

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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.

View File

@ -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;
}
}

View File

@ -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
{

View File

@ -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

View File

@ -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