-
Notifications
You must be signed in to change notification settings - Fork 719
Do not allocate String to check if HTTP message is keep alive #402
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ import NIO | |
| let crlf: StaticString = "\r\n" | ||
| let headerSeparator: StaticString = ": " | ||
|
|
||
| private let connectionUtf8 = "connection".utf8 | ||
|
|
||
| // Keep track of keep alive state. | ||
| internal enum KeepAliveState { | ||
|
|
@@ -298,15 +297,16 @@ private extension UInt8 { | |
| case .keepAlive: | ||
| return true | ||
| case .unknown: | ||
| guard let connection = self["connection"].first?.lowercased() else { | ||
| // HTTP 1.1 use keep-alive by default if not otherwise told. | ||
| return version.major == 1 && version.minor == 1 | ||
| } | ||
|
|
||
| if connection == "close" { | ||
| return false | ||
| for header in self.headers { | ||
| if self.buffer.equalCaseInsensitiveASCII(view: "connection".utf8, at: header.name) { | ||
| if self.buffer.equalCaseInsensitiveASCII(view: "close".utf8, at: header.value) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is quite right, though to be fair this has never been quite right. Strictly speaking I think this will fail if the header is Do we want to add some tolerance for that, or set it as a contributor friendly issue and let the community tackle it?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Lukasa yes, commented on that one too but I'd be happy with a follow-up.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do a followup |
||
| return false | ||
| } | ||
| return self.buffer.equalCaseInsensitiveASCII(view: "keep-alive".utf8, at: header.value) | ||
| } | ||
| } | ||
| return connection == "keep-alive" | ||
| // HTTP 1.1 use keep-alive by default if not otherwise told. | ||
| return version.major == 1 && version.minor >= 1 | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -415,7 +415,7 @@ public struct HTTPHeaders: CustomStringConvertible { | |
| } | ||
|
|
||
| private func isConnectionHeader(_ header: HTTPHeaderIndex) -> Bool { | ||
| return self.buffer.equalCaseInsensitiveASCII(view: connectionUtf8, at: header) | ||
| return self.buffer.equalCaseInsensitiveASCII(view: "connection".utf8, at: header) | ||
| } | ||
|
|
||
| /// Add a header name/value pair to the block. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change the allocation counter test limits and reduce according to the number of allocs saved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weissi let me see if it changes anything (as it will only if we actual have a connection header).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weissi @Lukasa ok no changes as we never have such a header.