Skip to content

Use better default Accept-header for JDKHttpClient #1042

Description

@danielFesenmeyer

Currently the JDKHttpClient uses the following Accept header, if none is specified by the calling code: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

As described in a JDK issue [1], this causes problems with several server side libraries.

I had problems to get the device authorization flow working with Keycloak due to this issue.

What worked for me was extending OAuth20Service, and overriding the execute methods, and patching the request like that:
request.addHeader("Accept", "*/*");

The accept header */* is used per default by Postman and curl, so it seems to be a meaningful default - at least better than html, image and so on (afaik, scribejava is mostly dealing with JSON).

I would suggest to change method JDKHttpClient#prepareConnectionForBodyAndGetOutputStream to set this meaningful default Accept header, if none has been already set. [2]

[1] https://bugs.openjdk.org/browse/JDK-8163921
[2]

private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLConnection connection,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions