Merge remote-tracking branch 'origin/jetty-11.0.x' into jetty-12.0.x
# Conflicts: # jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ResourceService.java # jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java
This commit is contained in:
commit
f7d8ea67f6
|
@ -17,7 +17,6 @@ import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.InvalidPathException;
|
import java.nio.file.InvalidPathException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -326,7 +325,7 @@ public class ResourceService
|
||||||
String ifm = null;
|
String ifm = null;
|
||||||
String ifnm = null;
|
String ifnm = null;
|
||||||
String ifms = null;
|
String ifms = null;
|
||||||
long ifums = -1;
|
String ifums = null;
|
||||||
|
|
||||||
// Find multiple fields by iteration as an optimization
|
// Find multiple fields by iteration as an optimization
|
||||||
for (HttpField field : request.getHeaders())
|
for (HttpField field : request.getHeaders())
|
||||||
|
@ -338,7 +337,7 @@ public class ResourceService
|
||||||
case IF_MATCH -> ifm = field.getValue();
|
case IF_MATCH -> ifm = field.getValue();
|
||||||
case IF_NONE_MATCH -> ifnm = field.getValue();
|
case IF_NONE_MATCH -> ifnm = field.getValue();
|
||||||
case IF_MODIFIED_SINCE -> ifms = field.getValue();
|
case IF_MODIFIED_SINCE -> ifms = field.getValue();
|
||||||
case IF_UNMODIFIED_SINCE -> ifums = DateParser.parseDate(field.getValue());
|
case IF_UNMODIFIED_SINCE -> ifums = field.getValue();
|
||||||
default ->
|
default ->
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -348,7 +347,6 @@ public class ResourceService
|
||||||
|
|
||||||
if (_etags)
|
if (_etags)
|
||||||
{
|
{
|
||||||
|
|
||||||
String etag = content.getETagValue();
|
String etag = content.getETagValue();
|
||||||
if (etag != null)
|
if (etag != null)
|
||||||
{
|
{
|
||||||
|
@ -381,7 +379,7 @@ public class ResourceService
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle if modified since
|
// Handle if modified since
|
||||||
if (ifms != null)
|
if (ifms != null && ifnm == null)
|
||||||
{
|
{
|
||||||
//Get jetty's Response impl
|
//Get jetty's Response impl
|
||||||
String mdlm = content.getLastModifiedValue();
|
String mdlm = content.getLastModifiedValue();
|
||||||
|
@ -391,19 +389,31 @@ public class ResourceService
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ifmsl = request.getHeaders().getDateField(HttpHeader.IF_MODIFIED_SINCE);
|
long ifmsl = DateParser.parseDate(ifms);
|
||||||
if (ifmsl != -1 && Files.getLastModifiedTime(content.getResource().getPath()).toMillis() / 1000 <= ifmsl / 1000)
|
if (ifmsl != -1)
|
||||||
{
|
{
|
||||||
writeHttpError(request, response, callback, HttpStatus.NOT_MODIFIED_304);
|
long lm = content.getResource().lastModified().toEpochMilli();
|
||||||
return true;
|
if (lm != -1 && lm / 1000 <= ifmsl / 1000)
|
||||||
|
{
|
||||||
|
writeHttpError(request, response, callback, HttpStatus.NOT_MODIFIED_304);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the if[un]modified dates and compare to resource
|
// Parse the if[un]modified dates and compare to resource
|
||||||
if (ifums != -1 && Files.getLastModifiedTime(content.getResource().getPath()).toMillis() / 1000 > ifums / 1000)
|
if (ifums != null && ifm == null)
|
||||||
{
|
{
|
||||||
writeHttpError(request, response, callback, HttpStatus.PRECONDITION_FAILED_412);
|
long ifumsl = DateParser.parseDate(ifums);
|
||||||
return true;
|
if (ifumsl != -1)
|
||||||
|
{
|
||||||
|
long lm = content.getResource().lastModified().toEpochMilli();
|
||||||
|
if (lm != -1 && lm / 1000 > ifumsl / 1000)
|
||||||
|
{
|
||||||
|
writeHttpError(request, response, callback, HttpStatus.PRECONDITION_FAILED_412);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException iae)
|
catch (IllegalArgumentException iae)
|
||||||
|
|
|
@ -2539,6 +2539,20 @@ public class ResourceHandlerTest
|
||||||
|
|
||||||
assertThat(response.getStatus(), equalTo(304));
|
assertThat(response.getStatus(), equalTo(304));
|
||||||
assertThat(response.getContent(), is(""));
|
assertThat(response.getContent(), is(""));
|
||||||
|
|
||||||
|
response = HttpTester.parseResponse(
|
||||||
|
_local.getResponse("""
|
||||||
|
GET /context/simple.txt HTTP/1.1\r
|
||||||
|
Host: local\r
|
||||||
|
Connection: close\r
|
||||||
|
If-Modified-Since: %s\r
|
||||||
|
If-None-Match: XYZ \r
|
||||||
|
\r
|
||||||
|
""".formatted(lastModified)));
|
||||||
|
|
||||||
|
assertThat(response.getStatus(), equalTo(HttpStatus.OK_200));
|
||||||
|
assertThat(response.get(LAST_MODIFIED), notNullValue());
|
||||||
|
assertThat(response.getContent(), containsString("simple text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2572,6 +2586,18 @@ public class ResourceHandlerTest
|
||||||
\r
|
\r
|
||||||
""".formatted(lastModified)));
|
""".formatted(lastModified)));
|
||||||
assertThat(response.getStatus(), is(HttpStatus.PRECONDITION_FAILED_412));
|
assertThat(response.getStatus(), is(HttpStatus.PRECONDITION_FAILED_412));
|
||||||
|
|
||||||
|
response = HttpTester.parseResponse(_local.getResponse("""
|
||||||
|
GET /context/test-unmodified-since-file.txt HTTP/1.1\r
|
||||||
|
Host: local\r
|
||||||
|
Connection: close\r
|
||||||
|
If-Unmodified-Since: %s \r
|
||||||
|
If-Match: XYZ\r
|
||||||
|
\r
|
||||||
|
""".formatted(lastModified)));
|
||||||
|
assertThat(response.getStatus(), is(HttpStatus.OK_200));
|
||||||
|
assertThat(response.getContent(), equalTo("some content\nsome more content\n"));
|
||||||
|
assertThat(response.get(LAST_MODIFIED), notNullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -517,7 +517,7 @@ public class ResourceService
|
||||||
String ifm = null;
|
String ifm = null;
|
||||||
String ifnm = null;
|
String ifnm = null;
|
||||||
String ifms = null;
|
String ifms = null;
|
||||||
long ifums = -1;
|
String ifums = null;
|
||||||
|
|
||||||
if (request instanceof Request)
|
if (request instanceof Request)
|
||||||
{
|
{
|
||||||
|
@ -538,7 +538,7 @@ public class ResourceService
|
||||||
ifms = field.getValue();
|
ifms = field.getValue();
|
||||||
break;
|
break;
|
||||||
case IF_UNMODIFIED_SINCE:
|
case IF_UNMODIFIED_SINCE:
|
||||||
ifums = DateParser.parseDate(field.getValue());
|
ifums = field.getValue();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
@ -550,7 +550,7 @@ public class ResourceService
|
||||||
ifm = request.getHeader(HttpHeader.IF_MATCH.asString());
|
ifm = request.getHeader(HttpHeader.IF_MATCH.asString());
|
||||||
ifnm = request.getHeader(HttpHeader.IF_NONE_MATCH.asString());
|
ifnm = request.getHeader(HttpHeader.IF_NONE_MATCH.asString());
|
||||||
ifms = request.getHeader(HttpHeader.IF_MODIFIED_SINCE.asString());
|
ifms = request.getHeader(HttpHeader.IF_MODIFIED_SINCE.asString());
|
||||||
ifums = request.getDateHeader(HttpHeader.IF_UNMODIFIED_SINCE.asString());
|
ifums = request.getHeader(HttpHeader.IF_UNMODIFIED_SINCE.asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_etags)
|
if (_etags)
|
||||||
|
@ -605,7 +605,7 @@ public class ResourceService
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle if modified since
|
// Handle if modified since
|
||||||
if (ifms != null)
|
if (ifms != null && ifnm == null)
|
||||||
{
|
{
|
||||||
//Get jetty's Response impl
|
//Get jetty's Response impl
|
||||||
String mdlm = content.getLastModifiedValue();
|
String mdlm = content.getLastModifiedValue();
|
||||||
|
@ -615,19 +615,31 @@ public class ResourceService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ifmsl = request.getDateHeader(HttpHeader.IF_MODIFIED_SINCE.asString());
|
long ifmsl = DateParser.parseDate(ifms);
|
||||||
if (ifmsl != -1 && content.getResource().lastModified().toEpochMilli() <= ifmsl)
|
if (ifmsl != -1)
|
||||||
{
|
{
|
||||||
sendStatus(response, HttpServletResponse.SC_NOT_MODIFIED, content::getETagValue);
|
long lm = content.getResource().lastModified().toEpochMilli();
|
||||||
return false;
|
if (lm != -1 && lm / 1000 <= ifmsl / 1000)
|
||||||
|
{
|
||||||
|
sendStatus(response, HttpServletResponse.SC_NOT_MODIFIED, content::getETagValue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the if[un]modified dates and compare to resource
|
// Parse the if[un]modified dates and compare to resource
|
||||||
if (ifums != -1 && content.getResource().lastModified().toEpochMilli() > ifums)
|
if (ifums != null && ifm == null)
|
||||||
{
|
{
|
||||||
response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
|
long ifumsl = DateParser.parseDate(ifums);
|
||||||
return false;
|
if (ifumsl != -1)
|
||||||
|
{
|
||||||
|
long lm = content.getResource().lastModified().toEpochMilli();
|
||||||
|
if (lm != -1 && lm / 1000 > ifumsl / 1000)
|
||||||
|
{
|
||||||
|
response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException iae)
|
catch (IllegalArgumentException iae)
|
||||||
|
|
Loading…
Reference in New Issue