mirror of
https://github.com/apple/swift-http-types
synced 2026-11-25 04:47:48 +00:00
Field order should be insignificant between fields of different names
This commit is contained in:
1 parent
68deedb6b9
commit
4c7d1331a5
2 files changed
+66
-1
No files matched your search
@@ -108,7 +108,29 @@ public struct HTTPFields: Sendable, Hashable {
|
||||
}
|
||||
|
||||
static func == (lhs: _Storage, rhs: _Storage) -> Bool {
|
||||
lhs.fields.lazy.map(\.0) == rhs.fields.lazy.map(\.0)
|
||||
let leftFieldsIndex = lhs.ensureIndex
|
||||
let rightFieldsIndex = rhs.ensureIndex
|
||||
if leftFieldsIndex.count != rightFieldsIndex.count {
|
||||
return false
|
||||
}
|
||||
for (name, var leftIndex) in leftFieldsIndex {
|
||||
guard var rightIndex = rightFieldsIndex[name] else {
|
||||
return false
|
||||
}
|
||||
while leftIndex != .max && rightIndex != .max {
|
||||
let (leftField, leftNext) = lhs.fields[Int(leftIndex)]
|
||||
let (rightField, rightNext) = rhs.fields[Int(rightIndex)]
|
||||
if leftField != rightField {
|
||||
return false
|
||||
}
|
||||
leftIndex = leftNext
|
||||
rightIndex = rightNext
|
||||
}
|
||||
if leftIndex != rightIndex {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func append(field: HTTPField) {
|
||||
|
||||
@@ -73,6 +73,49 @@ final class HTTPTypesTests: XCTestCase {
|
||||
XCTAssertEqual(response2.headerFields[.server], "HTTPServer/1.0")
|
||||
}
|
||||
|
||||
func testComparison() {
|
||||
let fields1: HTTPFields = [
|
||||
.acceptEncoding: "br",
|
||||
.acceptEncoding: "gzip",
|
||||
.accept: "*/*",
|
||||
]
|
||||
XCTAssertNotEqual(fields1, [:])
|
||||
|
||||
let fields2: HTTPFields = [
|
||||
.acceptEncoding: "br",
|
||||
.acceptEncoding: "gzip",
|
||||
.accept: "*/*",
|
||||
]
|
||||
XCTAssertEqual(fields1, fields2)
|
||||
|
||||
let fields3: HTTPFields = [
|
||||
.acceptEncoding: "br",
|
||||
.accept: "*/*",
|
||||
.acceptEncoding: "gzip",
|
||||
]
|
||||
XCTAssertEqual(fields1, fields3)
|
||||
|
||||
let fields4: HTTPFields = [
|
||||
.acceptEncoding: "br",
|
||||
.accept: "*/*",
|
||||
]
|
||||
XCTAssertNotEqual(fields1, fields4)
|
||||
|
||||
let fields5: HTTPFields = [
|
||||
.acceptEncoding: "gzip",
|
||||
.acceptEncoding: "br",
|
||||
.accept: "*/*",
|
||||
]
|
||||
XCTAssertNotEqual(fields1, fields5)
|
||||
|
||||
let fields6: HTTPFields = [
|
||||
.acceptEncoding: "gzip",
|
||||
.acceptEncoding: "br",
|
||||
.acceptLanguage: "en",
|
||||
]
|
||||
XCTAssertNotEqual(fields1, fields6)
|
||||
}
|
||||
|
||||
func testSendable() {
|
||||
func isSendable(_ value: some Sendable) -> Bool { true }
|
||||
func isSendable(_ value: Any) -> Bool { false }
|
||||
|
||||
Reference in new issue
Block a user