[
https://issues.apache.org/jira/browse/CXF-8991?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Krzysztof Grabowski updated CXF-8991:
-------------------------------------
Description:
*Summary:* In Apache CXF version 3.6.3, the handling of content type for empty
requests defaults to a specific behavior that may not accommodate all use
cases, specifically when dealing with JSON content types. This enhancement
proposal aims to extend the {{determineContentType()}} method functionality to
better support scenarios where {{application/json}} content type should be
inferred or explicitly set for empty requests.
*Problem:* Currently, when making empty requests (no request body), the
{{HttpURLConnection}} does not set the {{Content-Type}} header unless
explicitly defined by the user. This behavior is controlled by the
{{setProtocolHeadersInConnection}} method, which defaults to setting the
content type to {{*/*}} or dropping it entirely for GET requests or when the
{{SET_EMPTY_REQUEST_CT_PROPERTY}} is explicitly set to false. This approach
does not account for situations where an empty request should imply a specific
content type, such as {{{}application/json{}}}, which is a common use case in
RESTful APIs.
*Proposed Improvement:* I suggest enhancing the {{determineContentType()}}
method to include logic that checks the request context or headers for
indications that {{application/json}} should be used as the content type for
empty requests. This would involve:
* Extending the logic within {{determineContentType()}} to infer
{{application/json}} when appropriate, possibly based on additional headers or
request properties indicating that the request is intended to be interpreted as
a JSON request
*Benefits:*
* Aligns Apache CXF's handling of content types for empty requests with common
RESTful API practices.
* Provides more intuitive behavior for API consumers and developers, reducing
the need for workarounds to explicitly set content types for empty JSON
requests.
* Enhances the framework's flexibility in handling various content types,
particularly for APIs that predominantly use JSON.
*Impact:* This change is expected to improve Apache CXF's usability for
developers working with JSON-centric APIs, making it easier to comply with API
contracts that expect specific content types for all requests, including those
without a body.
----
was:
*Summary:* In Apache CXF version 3.6.3, the handling of content type for empty
requests defaults to a specific behavior that may not accommodate all use
cases, specifically when dealing with JSON content types. This enhancement
proposal aims to extend the {{determineContentType()}} method functionality to
better support scenarios where {{application/json}} content type should be
inferred or explicitly set for empty requests.
*Problem:* Currently, when making empty requests (no request body), the
{{HttpURLConnection}} does not set the {{Content-Type}} header unless
explicitly defined by the user. This behavior is controlled by the
{{setProtocolHeadersInConnection}} method, which defaults to setting the
content type to {{*/*}} or dropping it entirely for GET requests or when the
{{SET_EMPTY_REQUEST_CT_PROPERTY}} is explicitly set to false. This approach
does not account for situations where an empty request should imply a specific
content type, such as {{{}application/json{}}}, which is a common use case in
RESTful APIs.
*Proposed Improvement:* I suggest enhancing the {{determineContentType()}}
method to include logic that checks the request context or headers for
indications that {{application/json}} should be used as the content type for
empty requests. This would involve:
* Extending the logic within {{determineContentType()}} to infer
{{application/json}} when appropriate, possibly based on additional headers or
request properties indicating that the request is intended to be interpreted as
a JSON request.
* Updating {{setProtocolHeadersInConnection}} to accommodate this new logic,
ensuring that empty requests can implicitly or explicitly be set to use
{{application/json}} as the content type when no other content type is
specified.
*Benefits:*
* Aligns Apache CXF's handling of content types for empty requests with common
RESTful API practices.
* Provides more intuitive behavior for API consumers and developers, reducing
the need for workarounds to explicitly set content types for empty JSON
requests.
* Enhances the framework's flexibility in handling various content types,
particularly for APIs that predominantly use JSON.
*Impact:* This change is expected to improve Apache CXF's usability for
developers working with JSON-centric APIs, making it easier to comply with API
contracts that expect specific content types for all requests, including those
without a body.
----
> Enhancement: Determine Content Type for Empty Requests with Consideration for
> `application/json`
> ------------------------------------------------------------------------------------------------
>
> Key: CXF-8991
> URL: https://issues.apache.org/jira/browse/CXF-8991
> Project: CXF
> Issue Type: Improvement
> Components: Core
> Affects Versions: 3.6.3
> Reporter: Krzysztof Grabowski
> Priority: Trivial
>
> *Summary:* In Apache CXF version 3.6.3, the handling of content type for
> empty requests defaults to a specific behavior that may not accommodate all
> use cases, specifically when dealing with JSON content types. This
> enhancement proposal aims to extend the {{determineContentType()}} method
> functionality to better support scenarios where {{application/json}} content
> type should be inferred or explicitly set for empty requests.
> *Problem:* Currently, when making empty requests (no request body), the
> {{HttpURLConnection}} does not set the {{Content-Type}} header unless
> explicitly defined by the user. This behavior is controlled by the
> {{setProtocolHeadersInConnection}} method, which defaults to setting the
> content type to {{*/*}} or dropping it entirely for GET requests or when the
> {{SET_EMPTY_REQUEST_CT_PROPERTY}} is explicitly set to false. This approach
> does not account for situations where an empty request should imply a
> specific content type, such as {{{}application/json{}}}, which is a common
> use case in RESTful APIs.
> *Proposed Improvement:* I suggest enhancing the {{determineContentType()}}
> method to include logic that checks the request context or headers for
> indications that {{application/json}} should be used as the content type for
> empty requests. This would involve:
> * Extending the logic within {{determineContentType()}} to infer
> {{application/json}} when appropriate, possibly based on additional headers
> or request properties indicating that the request is intended to be
> interpreted as a JSON request
> *Benefits:*
> * Aligns Apache CXF's handling of content types for empty requests with
> common RESTful API practices.
> * Provides more intuitive behavior for API consumers and developers,
> reducing the need for workarounds to explicitly set content types for empty
> JSON requests.
> * Enhances the framework's flexibility in handling various content types,
> particularly for APIs that predominantly use JSON.
> *Impact:* This change is expected to improve Apache CXF's usability for
> developers working with JSON-centric APIs, making it easier to comply with
> API contracts that expect specific content types for all requests, including
> those without a body.
> ----
--
This message was sent by Atlassian Jira
(v8.20.10#820010)