Skip to content

Commit

Permalink
Support content type application/x-ndjson in DeprecationRestHandler
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jakelandis committed Nov 29, 2018
1 parent 4652337 commit 6f25b17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c
handler.handleRequest(request, channel, client);
}

@Override
public boolean supportsContentStream() {
return handler.supportsContentStream();
}

/**
* This does a very basic pass at validating that a header's value contains only expected characters according to RFC-5987, and those
* that it references.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* Tests {@link DeprecationRestHandler}.
Expand Down Expand Up @@ -114,6 +115,13 @@ public void testInvalidHeaderValueEmpty() {
expectThrows(IllegalArgumentException.class, () -> DeprecationRestHandler.requireValidHeader(blank));
}

public void testSupportsContentStream() {
DeprecationRestHandler deprecationRestHandler = new DeprecationRestHandler(handler, deprecationMessage, deprecationLogger);
when(handler.supportsContentStream()).thenReturn(true).thenReturn(false);
assertTrue(deprecationRestHandler.supportsContentStream());
assertFalse(deprecationRestHandler.supportsContentStream());
}

/**
* {@code ASCIIHeaderGenerator} only uses characters expected to be valid in headers (simplified US-ASCII).
*/
Expand Down

0 comments on commit 6f25b17

Please sign in to comment.