Skip to content
Open
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
11 changes: 8 additions & 3 deletions Sources/NIOHTTP1/HTTPTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,14 @@ extension HTTPResponseHead {
}
}

extension UInt8 {
extension String.UTF8View {
/// Determines if this `UTF8View` corresponds to an `String` which contains only ASCII characters.
fileprivate var isASCII: Bool {
self <= 127
var result: UInt8 = 0
for byte in self {
result |= byte
}
return result <= 127
}
}

Expand Down Expand Up @@ -361,7 +366,7 @@ public struct HTTPHeaders: CustomStringConvertible, ExpressibleByDictionaryLiter
/// recommended.
/// - Parameter value: The header field value to add for the given name.
public mutating func add(name: String, value: String) {
precondition(!name.utf8.contains(where: { !$0.isASCII }), "name must be ASCII")
precondition(!name.utf8.isASCII, "name must be ASCII")
self.headers.append((name, value))
if self.isConnectionHeader(name) {
self.keepAliveState = .unknown
Expand Down