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

Remove Content-Type Header when request with empty body POST method #2555

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jay-choe
Copy link

@jay-choe jay-choe commented Sep 18, 2024

Hi.

I have looked this issue and got an idea to deal with.

In current code, convert null body to not null and it write to outputstream.

In that process, when writing empty string in outputstream, unwanted Content-Type Header is added which is ''application/x-www-form-urlencoded".

So, I rearrange null body code to avoid unwanted header.

With this, Content-Length header is not set, so I added. But, this header is restricted header so 'sun.net.http.allowRestrictedHeaders' system property should be true to add content-length header.

And this property should be set before client class loaded. I guess there is no suitable way to inject restricted header to connection.

Feel Free to comment this idea. thanks.

…Default Client).

- add Content-Length Header with 0 value when `sun.net.http.allowRestrictedHeaders` System Property is set true

- fix not running test to run
@jay-choe jay-choe force-pushed the remove-content-type-header-with-empty-post-body branch from 6928474 to bbec180 Compare September 18, 2024 10:19
@jay-choe jay-choe force-pushed the remove-content-type-header-with-empty-post-body branch from 30079f9 to 21ed9eb Compare September 18, 2024 15:35
@kdavisk6
Copy link
Member

kdavisk6 commented Oct 4, 2024

This look good. Could you please add some information to the README to indicate how to take advantage of this change, helping folks understand the System Property requirement?

@kdavisk6 kdavisk6 added ready to merge Will be merged if no other member ask for changes feedback provided Feedback has been provided to the author labels Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback provided Feedback has been provided to the author ready to merge Will be merged if no other member ask for changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants