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

Use better default Accept-header for JDKHttpClient #1042

Open
danielFesenmeyer opened this issue Jun 30, 2022 · 0 comments
Open

Use better default Accept-header for JDKHttpClient #1042

danielFesenmeyer opened this issue Jun 30, 2022 · 0 comments

Comments

@danielFesenmeyer
Copy link

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,

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

1 participant