Skip to content

Conversation

DaveCTurner
Copy link
Contributor

This method only exists to add some additional Content-type
validation, but we can do all the validation needed using
RestHandler#mediaTypesValid instead.

This method only exists to add some additional `Content-type`
validation, but we can do all the validation needed using
`RestHandler#mediaTypesValid` instead.
@DaveCTurner DaveCTurner requested a review from mhl-b October 3, 2025 10:34
@DaveCTurner DaveCTurner requested a review from a team as a code owner October 3, 2025 10:34
@DaveCTurner DaveCTurner added >non-issue :Distributed Coordination/Network Http and internode communication implementations v9.3.0 labels Oct 3, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Coordination Meta label for Distributed Coordination team label Oct 3, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

Copy link
Contributor

@mhl-b mhl-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

But I would slap this check on XContentType enum.

    public static boolean isAnyOf(XContentType t, List<XContentType> ts) {
        if (t == null) return false;
        return ts.contains(t);
    }

    public static boolean isJsonOrSmile(XContentType t) {
        return isAnyOf(t, List.of(JSON, SMILE));
    }

Also remove indirection of hasValidMediaTypeForBulkRequest, saying isJsonOrSmile. RestBulkAction imports look odd here.

    public boolean mediaTypesValid(RestRequest request) {
        return XContentType.isJsonOrSmile(request.getXContentType());
    }

@DaveCTurner
Copy link
Contributor Author

Yeah fair point this isn't just about RestBulkHandler and derivatives really. Slightly different approach, see d282db9.

Copy link
Contributor

@mhl-b mhl-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat

RestResponse.createSimpleErrorResponse(
channel,
RestStatus.NOT_ACCEPTABLE,
"Content-Type [" + xContentType + "] does not support stream parsing. Use JSON or SMILE instead"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new version will return a generic unsupported type error rather than "stream parsing" error, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it will say Content-Type header [...] is not supported instead, with a (technically incorrect) 406 Not Acceptable either way.

@DaveCTurner DaveCTurner added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Oct 6, 2025
@elasticsearchmachine elasticsearchmachine merged commit 5024169 into elastic:main Oct 6, 2025
34 checks passed
@DaveCTurner DaveCTurner deleted the 2025/10/03/supportsBulkContent-unnecessary branch October 6, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed Coordination/Network Http and internode communication implementations >non-issue Team:Distributed Coordination Meta label for Distributed Coordination team v9.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants