Skip to content

Commit b58291e

Browse files
authored
Add Metadata collection (#1683)
1 parent f37ce30 commit b58291e

File tree

7 files changed

+1365
-3
lines changed

7 files changed

+1365
-3
lines changed

NOTICES.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,29 @@ It also uses derivations of SwiftNIO's lock 'NIOLock.swift' and locked value box
3131

3232
---
3333

34+
This product uses derivations of SwiftNIOHTTP2's implementation of case
35+
insensitive comparison of strings, found in 'HPACKHeader.swift'.
36+
37+
* LICENSE (Apache License 2.0):
38+
* https://github.com/apple/swift-nio-http2/blob/main/LICENSE.txt
39+
* HOMEPAGE:
40+
* https://github.com/apple/swift-nio-http2
41+
42+
---
43+
3444
This product contains a derivation of the backpressure aware async stream from
3545
the Swift project.
3646

3747
* LICENSE (Apache License 2.0):
3848
* https://github.com/apple/swift/blob/main/LICENSE.txt
3949
* HOMEPAGE:
4050
* https://github.com/apple/swift
51+
52+
---
53+
54+
This product uses derivations of swift-extras/swift-extras-base64 'Base64.swift'.
55+
56+
* LICENSE (Apache License 2.0):
57+
* https://github.com/swift-extras/swift-extras-base64/blob/main/LICENSE
58+
* HOMEPAGE:
59+
* https://github.com/swift-extras/swift-extras-base64

Sources/GRPCCore/Internal/Base64.swift

Lines changed: 605 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2023, gRPC Authors All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
//===----------------------------------------------------------------------===//
17+
//
18+
// This source file is part of the SwiftNIO open source project
19+
//
20+
// Copyright (c) 2017-2023 Apple Inc. and the SwiftNIO project authors
21+
// Licensed under Apache License v2.0
22+
//
23+
// See LICENSE.txt for license information
24+
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
25+
//
26+
// SPDX-License-Identifier: Apache-2.0
27+
//
28+
//===----------------------------------------------------------------------===//
29+
30+
extension UInt8 {
31+
@inlinable
32+
var isASCII: Bool {
33+
return self <= 127
34+
}
35+
}
36+
37+
extension String.UTF8View {
38+
/// Compares two UTF8 strings as case insensitive ASCII bytes.
39+
///
40+
/// - Parameter bytes: The string constant in the form of a collection of `UInt8`
41+
/// - Returns: Whether the collection contains **EXACTLY** this array or no, but by ignoring case.
42+
@inlinable
43+
func compareCaseInsensitiveASCIIBytes(to other: String.UTF8View) -> Bool {
44+
// fast path: we can get the underlying bytes of both
45+
let maybeMaybeResult = self.withContiguousStorageIfAvailable { lhsBuffer -> Bool? in
46+
other.withContiguousStorageIfAvailable { rhsBuffer in
47+
if lhsBuffer.count != rhsBuffer.count {
48+
return false
49+
}
50+
51+
for idx in 0 ..< lhsBuffer.count {
52+
// let's hope this gets vectorised ;)
53+
if lhsBuffer[idx] & 0xdf != rhsBuffer[idx] & 0xdf && lhsBuffer[idx].isASCII {
54+
return false
55+
}
56+
}
57+
return true
58+
}
59+
}
60+
61+
if let maybeResult = maybeMaybeResult, let result = maybeResult {
62+
return result
63+
} else {
64+
return self._compareCaseInsensitiveASCIIBytesSlowPath(to: other)
65+
}
66+
}
67+
68+
@inlinable
69+
@inline(never)
70+
func _compareCaseInsensitiveASCIIBytesSlowPath(to other: String.UTF8View) -> Bool {
71+
return self.elementsEqual(other, by: { return (($0 & 0xdf) == ($1 & 0xdf) && $0.isASCII) })
72+
}
73+
}
74+
75+
extension String {
76+
@inlinable
77+
func isEqualCaseInsensitiveASCIIBytes(to: String) -> Bool {
78+
return self.utf8.compareCaseInsensitiveASCIIBytes(to: to.utf8)
79+
}
80+
}

0 commit comments

Comments
 (0)