Skip to content
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

Empty 'Accept' header is added to request if the input is null or an empty string #4407

Open
rseidlnc opened this issue Mar 10, 2020 · 2 comments

Comments

@rseidlnc
Copy link

rseidlnc commented Mar 10, 2020

Hello!

We're currently using the jersey-client-2.25.1 in our project and we did an update of the openapi-generator-cli-4.2.3 for generating our api clients.

In the old version of the generator the parameter for the accept header for a DELETE request looked like this:

    final String[] localVarAccepts = {
      "application/json", "application/xml"
    };

in the new version they changed it to:

    final String[] localVarAccepts = {
      
    };

The values of these arrays were merged to a comma separated string and passed to the accept method of the ClientRequest.class:

    /**
     * Add new accepted types to the message headers.
     *
     * @param types accepted types to be added.
     */
    public void accept(final String... types) {
        getHeaders().addAll(HttpHeaders.ACCEPT, (Object[]) types);
    }

The problem is that the REST web service which we're targeting can't handle empty 'Accept' headers, and in my opinion it shouldn't be able to, since the 'Accept' header shouldn't be set on the DELETE request if the input value is empty or null. Therefore it would be great if there is a way to tell Jersey not to add the default value or an empty header when a null or an empty string is used.

@jansupol
Copy link
Contributor

jansupol commented Mar 11, 2020

In 2.25.1, there used to work HeaderDelegateProvider SPI that may help you. Just the first idea without fully understanding the problem.

The other possibility is to add a @PreMatching ContainerRequestContext that would remove the empty/null header before the request hits your service. Or perhaps ClientRequestFilter with priority after the generator.

@jansupol
Copy link
Contributor

Therefore it would be great if there is a way to tell Jersey not to add the default value or an empty header when a null or an empty string is used.

This is tricky. Filtering the accept method values is possible, but it will not work in cases where getHeaders().add(HttpHeaders.ACCEPT, ""); is called directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants