ResponseWriter.java (vaadin-flow-4.0.5) | : | ResponseWriter.java (vaadin-flow-4.0.6) | ||
---|---|---|---|---|
skipping to change at line 54 | skipping to change at line 54 | |||
/** | /** | |||
* The class that handles writing the response data into the response. | * The class that handles writing the response data into the response. | |||
* | * | |||
* @author Vaadin Ltd | * @author Vaadin Ltd | |||
* @since 1.0. | * @since 1.0. | |||
*/ | */ | |||
public class ResponseWriter implements Serializable { | public class ResponseWriter implements Serializable { | |||
private static final int DEFAULT_BUFFER_SIZE = 32 * 1024; | private static final int DEFAULT_BUFFER_SIZE = 32 * 1024; | |||
private static final Pattern RANGE_HEADER_PATTERN = Pattern.compile("^bytes= | private static final Pattern RANGE_HEADER_PATTERN = Pattern.compile("^bytes= | |||
(([0-9]+-[0-9]+,?\\s*)+)$"); | (([0-9]*-[0-9]*,?\\s*)+)$"); | |||
private static final Pattern BYTE_RANGE_PATTERN = Pattern.compile("([0-9]+)- | private static final Pattern BYTE_RANGE_PATTERN = Pattern.compile("([0-9]*)- | |||
([0-9]+)"); | ([0-9]*)"); | |||
private final int bufferSize; | private final int bufferSize; | |||
private final boolean brotliEnabled; | private final boolean brotliEnabled; | |||
/** | /** | |||
* Create a response writer with the given deployment configuration. | * Create a response writer with the given deployment configuration. | |||
* | * | |||
* @param deploymentConfiguration | * @param deploymentConfiguration | |||
* the deployment configuration to use, not <code>null</code> | * the deployment configuration to use, not <code>null</code> | |||
*/ | */ | |||
skipping to change at line 201 | skipping to change at line 201 | |||
response.setStatus(416); // Range Not Satisfiable | response.setStatus(416); // Range Not Satisfiable | |||
return; | return; | |||
} | } | |||
String byteRanges = headerMatcher.group(1); | String byteRanges = headerMatcher.group(1); | |||
long resourceLength = connection.getContentLengthLong(); | long resourceLength = connection.getContentLengthLong(); | |||
Matcher rangeMatcher = BYTE_RANGE_PATTERN.matcher(byteRanges); | Matcher rangeMatcher = BYTE_RANGE_PATTERN.matcher(byteRanges); | |||
List<Pair<Long, Long>> ranges = new ArrayList<>(); | List<Pair<Long, Long>> ranges = new ArrayList<>(); | |||
while (rangeMatcher.find()) { | while (rangeMatcher.find()) { | |||
final long start = Long.parseLong(rangeMatcher.group(1)); | String startGroup = rangeMatcher.group(1); | |||
final long end = Long.parseLong(rangeMatcher.group(2)); | String endGroup = rangeMatcher.group(2); | |||
if (startGroup.isEmpty() && endGroup.isEmpty()) { | ||||
response.setContentLengthLong(0L); | ||||
response.setStatus(416); // Range Not Satisfiable | ||||
return; | ||||
} | ||||
long start = startGroup.isEmpty() ? 0L : Long.parseLong(startGroup); | ||||
long end = endGroup.isEmpty() ? Long.MAX_VALUE | ||||
: Long.parseLong(endGroup); | ||||
if (end < start | if (end < start | |||
|| (resourceLength >= 0 && start >= resourceLength)) { | || (resourceLength >= 0 && start >= resourceLength)) { | |||
// illegal range -> 416 | // illegal range -> 416 | |||
response.setContentLengthLong(0L); | response.setContentLengthLong(0L); | |||
response.setStatus(416); | response.setStatus(416); | |||
return; | return; | |||
} | } | |||
ranges.add(new Pair<>(start, end)); | ranges.add(new Pair<>(start, end)); | |||
} | } | |||
End of changes. 2 change blocks. | ||||
6 lines changed or deleted | 14 lines changed or added |