Repository navigation
Improve HTTP support for JDK client and HttpInvoker server - #1017
Merged
Merged
Conversation
Prior to this commit, HTTP clients relying on the JDK HTTP client would not properly reuse existing TCP connections (i.e. HTTP 1.1 persisten connection). The SimpleClientHttpResponse would close the actual connection once the response is handled. As explained in the JDK documentation (http://docs.oracle.com/javase/8/docs/technotes/guides/net/http-keepalive.html) HTTP clients should do the following to allow resource reuse: * consume the whole HTTP response content * close the response inputstream once done This commit makes sure that the response content is totally drained and then the stream closed (and not the connection). Issue: SPR-14040
Prior to this commit, the `HttpInvokerServiceExporter` would close its `ObjectOutputStream`, which itself issues duplicate flushes on the underlying `OutputStream`. Duplicate flushes can lead to multiple, separate TCP packets where those should be gathered writes. This commit wraps the underying stream with a decorator that guards against flush calls that are duplicated with the one done in `close`. Issue: SPR-14040
|
This render InputStreamResource created by ResourceHttpMessageConverter unusable. A solution could be to skip InputStreamResource altogether, I don't know if it would have side effects. @Override
public void close() { public void close() {
- this.connection.disconnect(); + if (this.responseStream != null) {
+ try {
+ StreamUtils.drain(this.responseStream);
+ this.responseStream.close();
+ }
+ catch (IOException e) { }
+ }
} } |
Member
Author
|
@hadrienk Could you create a new issue on jira.spring.io and reference Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two commits that improve HTTP support when using the native JDK HTTP architecture.
The first commit prevents the RestTemplate from closing the underlying HTTP connection when closing an HTTP response and completely drains the content of the response. Those are the two conditions to really leverage HTTP persistent connections support in HTTP 1.1.
The second commit works around a JDK API that seems to artificially prevent gathered writes when using the HttpInvoker server implementation.
Issue: SPR-14040