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
3 changes: 3 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ Changes log
first scope outermost. `McpRequestContext.transportResponse()` gives the transport
response.
- Bugs fixed
- 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 (#1734).
- 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 (#1712).
- An MCP request whose `MCP-Protocol-Version` header is neither 2026-07-28 nor 2025-11-25,
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");
}
}