Skip to content
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

Add Metadata collection #1683

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions NOTICES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,29 @@ It also uses derivations of SwiftNIO's lock 'NIOLock.swift' and locked value box

---

This product uses derivations of SwiftNIOHTTP2's implementation of case
insensitive comparison of strings, found in 'HPACKHeader.swift'.

* LICENSE (Apache License 2.0):
* https://github.com/apple/swift-nio-http2/blob/main/LICENSE.txt
* HOMEPAGE:
* https://github.com/apple/swift-nio-http2

---

This product contains a derivation of the backpressure aware async stream from
the Swift project.

* LICENSE (Apache License 2.0):
* https://github.com/apple/swift/blob/main/LICENSE.txt
* HOMEPAGE:
* https://github.com/apple/swift

---

This product uses derivations of swift-extras/swift-extras-base64 'Base64.swift'.

* LICENSE (Apache License 2.0):
* https://github.com/swift-extras/swift-extras-base64/blob/main/LICENSE
* HOMEPAGE:
* https://github.com/swift-extras/swift-extras-base64
605 changes: 605 additions & 0 deletions Sources/GRPCCore/Internal/Base64.swift

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions Sources/GRPCCore/Internal/String+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2023, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2023 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

extension UInt8 {
@inlinable
var isASCII: Bool {
return self <= 127
}
}

extension String.UTF8View {
/// Compares two UTF8 strings as case insensitive ASCII bytes.
///
/// - Parameter bytes: The string constant in the form of a collection of `UInt8`
/// - Returns: Whether the collection contains **EXACTLY** this array or no, but by ignoring case.
@inlinable
func compareCaseInsensitiveASCIIBytes(to other: String.UTF8View) -> Bool {
// fast path: we can get the underlying bytes of both
let maybeMaybeResult = self.withContiguousStorageIfAvailable { lhsBuffer -> Bool? in
other.withContiguousStorageIfAvailable { rhsBuffer in
if lhsBuffer.count != rhsBuffer.count {
return false
}

for idx in 0 ..< lhsBuffer.count {
// let's hope this gets vectorised ;)
if lhsBuffer[idx] & 0xdf != rhsBuffer[idx] & 0xdf && lhsBuffer[idx].isASCII {
return false
}
}
return true
}
}

if let maybeResult = maybeMaybeResult, let result = maybeResult {
return result
} else {
return self._compareCaseInsensitiveASCIIBytesSlowPath(to: other)
}
}

@inlinable
@inline(never)
func _compareCaseInsensitiveASCIIBytesSlowPath(to other: String.UTF8View) -> Bool {
return self.elementsEqual(other, by: { return (($0 & 0xdf) == ($1 & 0xdf) && $0.isASCII) })
}
}

extension String {
@inlinable
func isEqualCaseInsensitiveASCIIBytes(to: String) -> Bool {
return self.utf8.compareCaseInsensitiveASCIIBytes(to: to.utf8)
}
}
Loading