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

Triple http limiting the size of the HTTP request and response #14246

Merged
merged 12 commits into from
Jun 11, 2024

Conversation

finefuture
Copy link
Contributor

What is the purpose of the change

refer: #14068

  1. When an HttpStatusException occurs during serialization, It does not need to be wrapped as an EncodeException
  2. Use LimitedByteBufOutputStream to limit the size of the write data. Throws an HttpOverPayloadException when the limit is exceeded
  3. Fix some typos

For example:

        tripleProtocol.setTriple(TripleBuilder.newBuilder()
                .maxBodySize(50)
                .maxResponseBodySize(100)
                .build());

Success result:
image

Request body limit result:
image

Response body limit result:
image

Brief changelog

Verifying this change

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Add some description to dubbo-website project if you are requesting to add a feature.
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.

@finefuture
Copy link
Contributor Author

@oxsean PTAL

# Conflicts:
#	dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h1/NettyHttp1Channel.java
@oxsean
Copy link
Collaborator

oxsean commented May 31, 2024

I think h2 respone also need limit respone size.

@finefuture
Copy link
Contributor Author

In http2:

  1. In case of serialization failure, add tri-status and tri-message in trailers to indicate the reason for failure, and keep the header code as 200, or serialize first and then send the header frame for unary calls?
  2. Can content-length be placed in trailers? Is it necessary to place it? Or provide configuration to write content-length?

@finefuture
Copy link
Contributor Author

finefuture commented Jun 4, 2024

A problem encountered is that errors may occur during serialization. At this time, if the header is written first, the status code will be 200, but the result is failure.
Since both http1 and http2 currently only have unary calls, we can write the header after serialization is complete, which senses that serialization failed and returns a code of 500.

@finefuture
Copy link
Contributor Author

Http2 no longer requires a content-length header, but some clients may use content-length to determine whether the data stream is complete. Therefore, refer to some common implementations in the industry to decide whether to add a content-length header to the http2 trailers, such as spring boot, tomcat, etc.

…g should also be set when the http1 connection is disconnected
@finefuture
Copy link
Contributor Author

New results
http2:
image
http1:
image

# Conflicts:
#	dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h1/NettyHttp1Channel.java
#	dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h2/NettyH2StreamChannel.java
@finefuture finefuture requested a review from oxsean June 7, 2024 08:47
@oxsean
Copy link
Collaborator

oxsean commented Jun 7, 2024

LGTM.

@AlbumenJ
Copy link
Member

@EarthChen PTAL

Copy link
Member

@EarthChen EarthChen left a comment

Choose a reason for hiding this comment

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

LGTM

@EarthChen EarthChen merged commit 5d5d036 into apache:3.3 Jun 11, 2024
15 of 17 checks passed
Copy link

sonarcloud bot commented Jun 11, 2024

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.

None yet

4 participants