opensearch-project / opensearch-project/opensearch-java

[BUG] Headers provided in the request are not respected in the RestClientTransport

Open
#1,234 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
165
Forks
250
Avg merge
1d 18h
Merged PRs (30d)
26

Description

What is the bug?

If you create a Request with headers, then send the request via the RestClientTransport, those headers are ignored, and not included in the request that is actually sent to opensearch.

How can one reproduce the bug?

Create any request to any endpoint and specify a header

    Request request =
            Requests.builder()
                    .endpoint(endpoint)
                    .headers(List.of(Map.entry("osd-xsrf", "true")))
                    .method(RestRequest.Method.POST.name())
                    .json(objectMapper.writeValueAsString(patternPayload))
                    .build();

send that request via the OpensearchGenericClient's execute() function, with the transport configured to use the RestClientTransport.

You will find that the sent message does not include this header, making it impossible to do things like create index patterns programmatically using the dashboards API. The issue is in prepareLowLevelRequest(), which does not merge the headers from the incoming request object, only creating new ones. I'm not sure if the same behavior occurs with the other transport clients.

What is the expected behavior?

If I provide headers in my request, those headers should also appear in the request made to Opensearch and should not be lost.

What is your host/environment?

Mac OS 14.6 -- Running Opensearch 2.19.0 in Kubernetes, and using the latest version of the opensearch-java library (2.15.0)

Do you have any screenshots?

N/A

Do you have any additional context?

Add any other context about the problem.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in prepareLowLevelRequest() within the RestClientTransport path, tracing requests passed through OpensearchGenericClient's execute() function. Reproduce the request with a custom header and verify that the outgoing request preserves the headers supplied on the incoming Request.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.