Merge remote-tracking branch 'origin/master' into jetty-http2
This commit is contained in:
commit
f93a409589
|
@ -612,7 +612,6 @@ package org.eclipse.jetty.http;
|
||||||
*/
|
*/
|
||||||
public class HttpStatus
|
public class HttpStatus
|
||||||
{
|
{
|
||||||
public final static int NOT_SET_000 = 0;
|
|
||||||
public final static int CONTINUE_100 = 100;
|
public final static int CONTINUE_100 = 100;
|
||||||
public final static int SWITCHING_PROTOCOLS_101 = 101;
|
public final static int SWITCHING_PROTOCOLS_101 = 101;
|
||||||
public final static int PROCESSING_102 = 102;
|
public final static int PROCESSING_102 = 102;
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
|
||||||
|
|
||||||
_rule.matchAndApply(_request.getRequestURI(), _request, _response);
|
_rule.matchAndApply(_request.getRequestURI(), _request, _response);
|
||||||
|
|
||||||
assertEquals(0,_response.getStatus());
|
assertEquals(200,_response.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1790,9 +1790,6 @@ public class Request implements HttpServletRequest
|
||||||
public void setHandled(boolean h)
|
public void setHandled(boolean h)
|
||||||
{
|
{
|
||||||
_handled = h;
|
_handled = h;
|
||||||
Response r=getResponse();
|
|
||||||
if (_handled && r.getStatus()==0)
|
|
||||||
r.setStatus(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class Response implements HttpServletResponse
|
||||||
private final HttpFields _fields = new HttpFields();
|
private final HttpFields _fields = new HttpFields();
|
||||||
private final AtomicInteger _include = new AtomicInteger();
|
private final AtomicInteger _include = new AtomicInteger();
|
||||||
private HttpOutput _out;
|
private HttpOutput _out;
|
||||||
private int _status = HttpStatus.NOT_SET_000;
|
private int _status = HttpStatus.OK_200;
|
||||||
private String _reason;
|
private String _reason;
|
||||||
private Locale _locale;
|
private Locale _locale;
|
||||||
private MimeTypes.Type _mimeType;
|
private MimeTypes.Type _mimeType;
|
||||||
|
@ -137,7 +137,7 @@ public class Response implements HttpServletResponse
|
||||||
|
|
||||||
protected void recycle()
|
protected void recycle()
|
||||||
{
|
{
|
||||||
_status = HttpStatus.NOT_SET_000;
|
_status = HttpStatus.OK_200;
|
||||||
_reason = null;
|
_reason = null;
|
||||||
_locale = null;
|
_locale = null;
|
||||||
_mimeType = null;
|
_mimeType = null;
|
||||||
|
@ -1290,8 +1290,6 @@ public class Response implements HttpServletResponse
|
||||||
|
|
||||||
protected ResponseInfo newResponseInfo()
|
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());
|
return new ResponseInfo(_channel.getRequest().getHttpVersion(), _fields, getLongContentLength(), getStatus(), getReason(), _channel.getRequest().isHead());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
Response response = request.getResponse();
|
||||||
switch (response.getStatus() / 100)
|
if (request.isHandled())
|
||||||
{
|
{
|
||||||
case 0:
|
switch (response.getStatus() / 100)
|
||||||
if (request.isHandled())
|
{
|
||||||
|
case 1:
|
||||||
|
_responses1xx.incrementAndGet();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
_responses2xx.incrementAndGet();
|
_responses2xx.incrementAndGet();
|
||||||
else
|
break;
|
||||||
|
case 3:
|
||||||
|
_responses3xx.incrementAndGet();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
_responses4xx.incrementAndGet();
|
_responses4xx.incrementAndGet();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 5:
|
||||||
_responses1xx.incrementAndGet();
|
_responses5xx.incrementAndGet();
|
||||||
break;
|
break;
|
||||||
case 2:
|
default:
|
||||||
_responses2xx.incrementAndGet();
|
break;
|
||||||
break;
|
}
|
||||||
case 3:
|
|
||||||
_responses3xx.incrementAndGet();
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
_responses4xx.incrementAndGet();
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
_responses5xx.incrementAndGet();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
// will fall through to not found handler
|
||||||
|
_responses4xx.incrementAndGet();
|
||||||
_responsesTotalBytes.addAndGet(response.getContentCount());
|
_responsesTotalBytes.addAndGet(response.getContentCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
|
@ -191,11 +192,21 @@ public class ServletTester extends ContainerLifeCycle
|
||||||
{
|
{
|
||||||
return _connector.getResponses(request);
|
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
|
public ByteBuffer getResponses(ByteBuffer request) throws Exception
|
||||||
{
|
{
|
||||||
return _connector.getResponses(request);
|
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.
|
/** Create a port based connector.
|
||||||
|
|
|
@ -688,6 +688,35 @@ public class URIUtil
|
||||||
url.append(':').append(port);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class FileResource extends Resource
|
||||||
|
|
||||||
_file=file;
|
_file=file;
|
||||||
_uri=normalizeURI(_file,url.toURI());
|
_uri=normalizeURI(_file,url.toURI());
|
||||||
_alias=checkAlias(_file);
|
_alias=checkFileAlias(_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------- */
|
/* -------------------------------------------------------- */
|
||||||
|
@ -108,17 +108,12 @@ public class FileResource extends Resource
|
||||||
_file=file;
|
_file=file;
|
||||||
URI file_uri=_file.toURI();
|
URI file_uri=_file.toURI();
|
||||||
_uri=normalizeURI(_file,uri);
|
_uri=normalizeURI(_file,uri);
|
||||||
|
|
||||||
if (!_uri.equals(file_uri.toString()))
|
// Is it a URI alias?
|
||||||
{
|
if (!URIUtil.equalsIgnoreEncodings(_uri,file_uri.toString()))
|
||||||
// URI and File URI are different. Is it just an encoding difference?
|
_alias=_file.toURI();
|
||||||
if (!file_uri.toString().equals(URIUtil.decodePath(uri.toString())))
|
|
||||||
_alias=_file.toURI();
|
|
||||||
else
|
|
||||||
_alias=checkAlias(_file);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
_alias=checkAlias(_file);
|
_alias=checkFileAlias(_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------- */
|
/* -------------------------------------------------------- */
|
||||||
|
@ -126,7 +121,7 @@ public class FileResource extends Resource
|
||||||
{
|
{
|
||||||
_file=file;
|
_file=file;
|
||||||
_uri=normalizeURI(_file,_file.toURI());
|
_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
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,9 +19,12 @@
|
||||||
package org.eclipse.jetty.util;
|
package org.eclipse.jetty.util;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +32,7 @@ import org.junit.Test;
|
||||||
/** Util meta Tests.
|
/** Util meta Tests.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class URITest
|
public class URIUtilTest
|
||||||
{
|
{
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
@Test
|
@Test
|
||||||
|
@ -185,6 +188,27 @@ public class URITest
|
||||||
assertEquals("parent null",null, URIUtil.parentPath(null));
|
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
|
@Test
|
|
@ -32,6 +32,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import org.eclipse.jetty.toolchain.test.OS;
|
import org.eclipse.jetty.toolchain.test.OS;
|
||||||
import org.eclipse.jetty.toolchain.test.TestingDir;
|
import org.eclipse.jetty.toolchain.test.TestingDir;
|
||||||
import org.eclipse.jetty.util.UrlEncoded;
|
import org.eclipse.jetty.util.UrlEncoded;
|
||||||
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Rule;
|
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")
|
@Ignore("Cannot get null to be seen by FileResource")
|
||||||
@Test
|
@Test
|
||||||
public void testExist_BadNull() throws Exception
|
public void testExist_BadNull() throws Exception
|
||||||
|
|
Loading…
Reference in New Issue