Skip to content

Commit 6f25b17

Browse files
committed
Support content type application/x-ndjson in DeprecationRestHandler
org.elasticsearch.rest.RestController#hasContentType checks to see if the RestHandler supports the `application/x-ndjson` Content-Type. DeprecationRestHandler is a wrapper around the real RestHandler, and prior to this change would always return `false` due to the interface's default supportsContentStream(). This prevents API's that use multi-line JSON from properly being deprecated resulting in an HTTP 406 error. This change ensures that the DeprecationRestHandler honors the supportsContentStream() of the wrapped RestHandler. Part of elastic#35958
1 parent 4652337 commit 6f25b17

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

server/src/main/java/org/elasticsearch/rest/DeprecationRestHandler.java

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c
6262
handler.handleRequest(request, channel, client);
6363
}
6464

65+
@Override
66+
public boolean supportsContentStream() {
67+
return handler.supportsContentStream();
68+
}
69+
6570
/**
6671
* This does a very basic pass at validating that a header's value contains only expected characters according to RFC-5987, and those
6772
* that it references.

server/src/test/java/org/elasticsearch/rest/DeprecationRestHandlerTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import static org.mockito.Mockito.inOrder;
3030
import static org.mockito.Mockito.mock;
31+
import static org.mockito.Mockito.when;
3132

3233
/**
3334
* Tests {@link DeprecationRestHandler}.
@@ -114,6 +115,13 @@ public void testInvalidHeaderValueEmpty() {
114115
expectThrows(IllegalArgumentException.class, () -> DeprecationRestHandler.requireValidHeader(blank));
115116
}
116117

118+
public void testSupportsContentStream() {
119+
DeprecationRestHandler deprecationRestHandler = new DeprecationRestHandler(handler, deprecationMessage, deprecationLogger);
120+
when(handler.supportsContentStream()).thenReturn(true).thenReturn(false);
121+
assertTrue(deprecationRestHandler.supportsContentStream());
122+
assertFalse(deprecationRestHandler.supportsContentStream());
123+
}
124+
117125
/**
118126
* {@code ASCIIHeaderGenerator} only uses characters expected to be valid in headers (simplified US-ASCII).
119127
*/

0 commit comments

Comments
 (0)