Skip to content

Accept header lost if transport initialized with LLRC RequestOptions #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
swallez opened this issue Aug 17, 2022 · 0 comments · Fixed by #380
Closed

Accept header lost if transport initialized with LLRC RequestOptions #377

swallez opened this issue Aug 17, 2022 · 0 comments · Fixed by #380
Labels
Category: Bug Something isn't working

Comments

@swallez
Copy link
Member

swallez commented Aug 17, 2022

Creating a RestClientTransport with a LLRC RequestOptions leads every request to fail with
co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/indices.create] failed: [media_type_header_exception] Invalid media-type value on headers [Accept, Content-Type]

How to reproduce

transport = new RestClientTransport(restClient, mapper)
    .withRequestOptions(new RestClientOptions.Builder(
        RequestOptions.DEFAULT.toBuilder()
        // add other options as needed
    ).build());
client = new ElasticsearchClient(transport);

Explanation

The Java API client sends a Content-Type: "application/vnd.elasticsearch+json;compatible-with=8" header with every request, and the ES server expects to see the same value for the Accept header. Setting custom RequestOptions override the Java API client built-in RequestOptions that sets this header.

Workaround

Manually set the Accept header:

transport = new RestClientTransport(restClient, mapper)
    .withRequestOptions(new RestClientOptions.Builder(
        RequestOptions.DEFAULT.toBuilder()
            .addHeader("Accept", "application/vnd.elasticsearch+json;compatible-with=8")
            // add other options as needed
    ).build());
client = new ElasticsearchClient(transport);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant