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

Unirest 4.x - Duplicate content-type header is being added for request #486

Closed
haroon-sheikh opened this issue Aug 2, 2023 · 7 comments
Closed

Comments

@haroon-sheikh
Copy link
Contributor

haroon-sheikh commented Aug 2, 2023

Describe the bug
Duplicate content-type is being added for a request with content-type header and body fields

To Reproduce
Steps to reproduce the behavior:

  1. When there's content-type=application/x-www-form-urlencoded set with body fields
  2. A failing test here Test for duplicate content-type headers #485

Expected behavior
A single content-type header is sent

Screenshots
If applicable, add screenshots to help explain your problem.

Environmental Data:

  • Java Version 11
  • Version [4.0.3]

Additional context
Add any other context about the problem here.

@haroon-sheikh
Copy link
Contributor Author

haroon-sheikh commented Aug 2, 2023

@ryber
Copy link
Collaborator

ryber commented Aug 2, 2023

Its only duplicate because you added it twice. Don't do that.

@haroon-sheikh
Copy link
Contributor Author

Sorry am I missing something, where am I adding it twice? Are you saying, I shouldn't be adding it at all?

@haroon-sheikh
Copy link
Contributor Author

Ah I see you've added a check. Thanks.

@ryber
Copy link
Collaborator

ryber commented Aug 2, 2023

Unirest has always automatically added the header, in the old 3 line there was a check that didn't auto-add it if it existed, so I pulled that into 4, but Unirest will still let you add multiple headers of the same type IF you want. The HTTP spec says you "shouldn't" do this and then points out exceptions to the rule, so from a tool standpoint, Unirest will let you do it.

Your code in the example really shouldn't add the header and let unirest just add it automatically.

@ryber ryber closed this as completed Aug 2, 2023
@ryber
Copy link
Collaborator

ryber commented Aug 2, 2023

fixed in 4.0.4

@haroon-sheikh
Copy link
Contributor Author

haroon-sheikh commented Aug 2, 2023

Thanks a lot for adding the check. It took me some good time to work out why it was failing.

We use an interceptor to log the request and responses but it looks like the interceptor on

config.getUniInterceptor().onRequest(request, config);
uses the request before the request is transformed and default headers are added so it's not actually what's being executed.

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