Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Sources/NIOHTTP1/HTTPTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import NIO
let crlf: StaticString = "\r\n"
let headerSeparator: StaticString = ": "
Copy link
Member

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

Copy link
Member Author

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).

Copy link
Member Author

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.


private let connectionUtf8 = "connection".utf8

// Keep track of keep alive state.
internal enum KeepAliveState {
Expand Down Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 Connection: close, some-other-header-name, when it should not. Additionally, neither close nor keep-alive strictly have to be first.

Do we want to add some tolerance for that, or set it as a contributor friendly issue and let the community tackle it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Lukasa @weissi I can fix this as part of this PR or do a followup ... Whatever you prefer. let me know.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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
}
}
}
Expand Down Expand Up @@ -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.
Expand Down