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

Fix: Ensure Content-Type is set based on header value if not explicitly set #1704

Merged

Conversation

KyrillosNageh
Copy link
Contributor

Fixes #1697

This PR ensures that the Content-Type is set based on the header value if it is not explicitly set by the user.

  • Modified the prepareRequestSpecs method to check if contentType is still ContentType.ANY.
  • If ContentType is not explicitly set by the user, it now retrieves the Content-Type from sessionHeaders and applies it directly to the RequestSpecBuilder.
  • This change ensures that the request uses the exact Content-Type provided in the headers, preventing encoding and serialization issues.

Kyrillos Nageh Abdelnour Flamon added 3 commits August 17, 2024 19:42
…ly set

- Modified the `prepareRequestSpecs` method to check if `contentType` is still `ContentType.ANY`.
- If `ContentType` is not explicitly set by the user, it now retrieves the `Content-Type` from `sessionHeaders` and applies it directly to the `RequestSpecBuilder`.
- This change ensures that the request uses the exact `Content-Type` provided in the headers, preventing encoding and serialization issues.
This update fixes issues where requests with XML or JSON bodies were not being encoded correctly due to the `contentType` defaulting to `ContentType.ANY`.
@KyrillosNageh KyrillosNageh marked this pull request as draft August 17, 2024 17:23
Copy link

codecov bot commented Aug 17, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 52.57%. Comparing base (5652a7c) to head (93c6e96).
Report is 1 commits behind head on main.

Files Patch % Lines
src/main/java/com/shaft/api/RestActions.java 33.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1704      +/-   ##
============================================
- Coverage     52.67%   52.57%   -0.11%     
  Complexity     1268     1268              
============================================
  Files           112      112              
  Lines          9993     9998       +5     
  Branches        962      964       +2     
============================================
- Hits           5264     5256       -8     
- Misses         4123     4138      +15     
+ Partials        606      604       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@MohabMohie MohabMohie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your valuable contribution!
Note that in the future it would be great if you can add a test class that can cover this case to ensure our code coverage doesn't decrease.

@MohabMohie MohabMohie marked this pull request as ready for review August 17, 2024 17:58
@MohabMohie MohabMohie merged commit dbe8015 into ShaftHQ:main Aug 17, 2024
3 of 4 checks passed
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

Successfully merging this pull request may close these issues.

[Bug]: (API) SOAP Request Fails Due to Improper Encoding of XML Content Type
2 participants