-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow sending
Connection: close
header (#4531)
* Allow sending `Connection: close` header Motivation: This PR aims to solve two problems with `Connection` header. 1. Allow sending `Connection` header field. HTTP/2 does not use the `Connection` header field. https://httpwg.org/specs/rfc9113.html#rfc.section.8.2.2 Hence, `Connection` header is prohibited and it is automatically stripped from headers. https://github.com/line/armeria/blob/b127cd27252f6a454130f66d1175a06faed01f09/core/src/main/java/com/linecorp/armeria/client/ClientOptions.java#L132-L132 There have been requets to close a connection after sending requests or responses on purpose or send `Connection: close` header for compatibility with legacy HTTP/1 servers. For HTTP/2, we can translate `Connection: close` as a signal to close a connection by sending a GOAWAY frame. It would be useful to rebalance HTTP/2 loads by closing connections after some periods. 2. Armeria server does not return `Connection:close` header when `Connection: close` is received. As a client sent `Connection: close` header, it seems fine not to return `Connection: close` header. However, returning the `Connection: close` header would be more compliant with HTTP/1.1 protocol. Modifications: - Removed `CONNECTION` header from prohibited header names. - Added `KeepAliveHandler.disconnectWhenFinished()` which is called when a `Connection: close` is specified in response headers. - Modified `HttpServerHandler` to check whether to close a connection when responses have been written. - Removed the singleton instance of `NoopKeepAliveHandler` and make to create an instance for each connection. - `NoopKeepAliveHandler` now has two fielders to know whether a channel needs immediate disconnection or the connection has to be closed after receving all responses in process. - Fixed `HttpChannelPool` to determine if a session is healthy using `isActive()`. This change allows inflights requests to use HTTP/2 sessions before GOAWAY is sent or received. - Fixed to correctly set keep alive headers for HTTP/1.1. Result: - You can now send `Connection: close` to close a connection after receiving a response. - Fixes #4471 - Fixes #4454 - Fixes #4131 * Update core/src/test/java/com/linecorp/armeria/client/CountingConnectionPoolListener.java Co-authored-by: jrhee17 <guins_j@guins.org> * Rename isActive() into canAcquire() and invoked deactivate() whenever disconnectWhenFinish() is called * Fix the flaky test * Address comments by @jrhee17 * Disallow acquring when a connection is about to disconnect * Allow only "connection: close" header * Add comments for connection shutdown mode * Address comments by @trustin * Add assert * Address comments by @jrhee17 * Fix recusive calls * Remove cruft --------- Co-authored-by: jrhee17 <guins_j@guins.org>
- Loading branch information
Showing
37 changed files
with
783 additions
and
279 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.