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

Relax validation for responses with empty content status. #5862

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

minwoox
Copy link
Member

@minwoox minwoox commented Aug 8, 2024

Motivation:
An exception is currently raised when aggregating a response if the response's status indicates empty content but content is present. However, a third-party legacy server might send a response with content despite an empty content status, which is beyond the client's control.

Modification:

  • Changed the behavior to log a debug message instead of raising an exception when content exists for a status that indicates empty content.

Result:

  • Armeria client now works with legacy servers that send content with an empty content status without raising exceptions.

Motivation:
An exception is currently raised when aggregating a response if the response's status indicates empty content but content is present.
However, a third-party legacy server might send a response with content despite an empty content status,
which is beyond the client's control.

Modification:
- Changed the behavior to log a debug message instead of raising an exception when content exists for a status that indicates empty content.

Result:
- Armeria client now works with legacy servers that send content with an empty content status without raising exceptions.
@minwoox minwoox added this to the 1.30.0 milestone Aug 8, 2024
Copy link

codecov bot commented Aug 8, 2024

Codecov Report

Attention: Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.

Project coverage is 74.61%. Comparing base (c7aca10) to head (6020bd4).
Report is 4 commits behind head on main.

Files Patch % Lines
...java/com/linecorp/armeria/common/HttpResponse.java 16.66% 4 Missing and 1 partial ⚠️
...om/linecorp/armeria/common/HttpResponseWriter.java 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5862      +/-   ##
============================================
+ Coverage     74.57%   74.61%   +0.04%     
- Complexity    21643    21693      +50     
============================================
  Files          1893     1896       +3     
  Lines         80153    80383     +230     
  Branches      10523    10575      +52     
============================================
+ Hits          59772    59980     +208     
- Misses        15341    15344       +3     
- Partials       5040     5059      +19     

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

if (!tryWrite(headers)) {
return;
}

// Add content if not empty.
if (!contentAlwaysEmpty && !content.isEmpty()) {
if (headers.status().isContentAlwaysEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to release the resource?

Suggested change
if (headers.status().isContentAlwaysEmpty()) {
if (headers.status().isContentAlwaysEmpty()) {
content.close();

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I missed that point.

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

👍👍

if (!tryWrite(headers)) {
return;
}

// Add content if not empty.
if (!contentAlwaysEmpty && !content.isEmpty()) {
if (headers.status().isContentAlwaysEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I missed that point.

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

👍 👍 👍

import com.linecorp.armeria.common.util.Exceptions;

final class HttpResponseUtil {

static final Logger logger = LoggerFactory.getLogger(HttpResponseUtil.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

optional) HttpResponseUtil seems like an package-private class which makes it susceptible to us refactoring this class without realizing that users are using this logger pattern

Copy link
Member Author

Choose a reason for hiding this comment

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

Add a comment for that. 😉

@ikhoon ikhoon merged commit faa886f into line:main Aug 9, 2024
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants