Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes log
- `DefaultSslContextFactory` now uses the JVM default algorithms for the trust manager (`TrustManagerFactory.getDefaultAlgorithm()`, `PKIX`) and the key manager (`KeyManagerFactory.getDefaultAlgorithm()`) instead of the obsolete `SunX509`, unless the `ssl.TrustManagerFactory.algorithm` or `ssl.KeyManagerFactory.algorithm` system property, the `trustManagerAlgorithm` or `keyManagerAlgorithm` parameter, or the setters say otherwise. A valid certificate chain that is not in order is no longer rejected with a "Certificate chaining error". The `PKIX` validation is the standard one, and stricter than `SunX509` on unusual chains: set the trust manager algorithm to `SunX509` to get the previous behavior. Issue #1397.
- `Redirector.getTargetRef()` now removes the dot segments (`.` and `..`) of the target URI (RFC 3986, section 5.2.4), so the `Location` header of a client redirection and the URI of a server redirection are normalized. Relative-path targets such as `../x` are left untouched, as they need their base reference. A reverse proxy built on `http://backend/root/{rr}` now resolves a `..` found in the remaining part itself, which it did not before the request reached the backend. Issue #238.
- The Jackson, Gson and JSON (org.json) converters now handle the `application/*+json` media types, such as `application/vnd.example+json`. They were ignored, so an incoming `+json` entity was not converted, and a `+json` response was left to another converter (such as JAXB) when it scored higher than the 0.5 given by Jackson. A custom converter that won for these media types may now lose to the JSON converters. Issue #1185.
- The `Range` header is now applied to GET requests only, as RFC 9110 section 14.2 requires: a HEAD request with a range was answered "206 Partial Content" (and so was OPTIONS), it is now answered as without the range. Issue #1734.
- A `CacheDirective` created by a factory, such as `CacheDirective.maxAge(60)`, now equals the same directive read from a header: `equals` and `hashCode` use the name and the value only, no longer the `digit` attribute, which has no effect on the written header. `isDigit()`, `setDigit(boolean)` and the constructor `CacheDirective(String, String, boolean)` are deprecated and will be removed in Restlet 3.0. Issue #1730.
- A 304 (Not Modified) response now carries the `Expires` header of the entity, as RFC 9110 section 15.4.5 requires, so that a revalidating cache refreshes it. Issue #1712.
- Misc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.Method;
import org.restlet.data.Range;
import org.restlet.data.Status;
import org.restlet.routing.Filter;
Expand Down Expand Up @@ -42,7 +43,9 @@ protected void afterHandle(Request request, Response response) {
if (!getRangeService().isEnabled()) {
return;
}
if (!request.getMethod().isSafe() || !response.isEntityAvailable()) {
// RFC 9110 section 14.2: GET is the only method for which range handling is defined, the
// Range header of any other method (HEAD, OPTIONS...) must be ignored.
if (!Method.GET.equals(request.getMethod()) || !response.isEntityAvailable()) {
return;
}
if (!response.getStatus().isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Request;
Expand Down Expand Up @@ -291,4 +293,31 @@ public void write(java.io.OutputStream outputStream)
void getRangeService_returnsApplicationRangeService() {
assertEquals(application.getRangeService(), filter.getRangeService());
}

/**
* RFC 9110 section 14.2: GET is the only method for which range handling is defined (#1734).
*/
@ParameterizedTest
@ValueSource(strings = {"HEAD", "OPTIONS", "TRACE"})
void afterHandle_rangeOnAnotherSafeMethod_isIgnored(String method) {
Response response =
successResponse(Method.valueOf(method), new StringRepresentation("0123456789"));
Representation original = response.getEntity();
response.getRequest().getRanges().add(new Range(0, 4));

filter.afterHandle(response.getRequest(), response);

assertEquals(Status.SUCCESS_OK, response.getStatus(), method);
assertEquals(original, response.getEntity(), method);
}

@Test
void afterHandle_rangeOnGet_stillGivesPartialContent() {
Response response = successResponse(Method.GET, new StringRepresentation("0123456789"));
response.getRequest().getRanges().add(new Range(0, 4));

filter.afterHandle(response.getRequest(), response);

assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.restlet.engine.application;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import java.net.URI;
import java.net.http.HttpClient;
Expand Down Expand Up @@ -156,4 +157,39 @@ void unsatisfiableRange_returns416WithTheCompleteLength(String range) throws Exc
assertEquals(416, response.statusCode(), range);
assertEquals("bytes */10", header(response, "Content-Range"), range);
}

private HttpResponse<String> send(String method, String range) throws Exception {
HttpRequest request =
HttpRequest.newBuilder(uri)
.method(method, HttpRequest.BodyPublishers.noBody())
.header("Range", range)
.build();
return client.send(request, BodyHandlers.ofString());
}

/**
* RFC 9110 section 14.2: the Range of a HEAD request is ignored, so it describes the full
* entity (#1734).
*/
@Test
void head_withRange_ignoresTheRange() throws Exception {
HttpResponse<String> response = send("HEAD", "bytes=0-3");

assertEquals(200, response.statusCode());
assertEquals("10", header(response, "Content-Length"));
assertEquals(null, header(response, "Content-Range"));
}

@Test
void options_withRange_ignoresTheRange() throws Exception {
HttpResponse<String> response = send("OPTIONS", "bytes=0-3");

assertNotEquals(206, response.statusCode());
assertEquals(null, header(response, "Content-Range"));
}

@Test
void get_withRange_stillReturnsPartialContent() throws Exception {
assertPartial("bytes=0-3", "0123", "bytes 0-3/10");
}
}
Loading