Skip to content

Commit 1fe651a

Browse files
committed
Merge branch 'main' into feature/add-websockets-event-types
2 parents c1af9de + 3ac078f commit 1fe651a

File tree

5 files changed

+94
-41
lines changed

5 files changed

+94
-41
lines changed

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
11
# Code of Conduct
22

3-
To be a truly great community, the SwiftAWSLambdaRuntime project needs to welcome developers from all walks of life, with different backgrounds, and with a wide range of experience. A diverse and friendly community will have more great ideas, more unique perspectives, and produce more great code. We will work diligently to make the SwiftAWSLambdaRuntime community welcoming to everyone.
4-
5-
To give clarity of what is expected of our members, this code of conduct is based on [contributor-covenant.org](http://contributor-covenant.org). This document is used across many open source communities, and we think it articulates our values well.
6-
7-
### Contributor Code of Conduct v1.4
8-
9-
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
10-
11-
Examples of behavior that contributes to creating a positive environment include:
12-
13-
* Using welcoming and inclusive language (e.g., prefer non-gendered words like “folks” to “guys”, non-ableist words like “soundness check” to “sanity check”, etc.)
14-
* Being respectful of differing viewpoints and experiences
15-
* Gracefully accepting constructive criticism
16-
* Focusing on what is best for the community
17-
* Showing empathy towards other community members
18-
19-
Examples of unacceptable behavior by participants include:
20-
21-
* The use of sexualized language or imagery and unwelcome sexual attention or advances
22-
* Trolling, insulting/derogatory comments, and personal or political attacks
23-
* Public or private harassment
24-
* Publishing others’ private information, such as a physical or electronic address, without explicit permission
25-
* Other conduct which could reasonably be considered inappropriate in a professional setting
26-
27-
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28-
29-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30-
31-
This Code of Conduct applies within all project spaces managed by the SwiftAWSLambdaRuntime project, including (but not limited to) source code repositories, bug trackers, web sites, documentation, and online forums. It also applies when an individual is representing the project or its community in public spaces. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
32-
33-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer at [[email protected]](mailto:[email protected]) or by flagging the behavior for moderation (e.g., in the Forums), whether you are the target of that behavior or not. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. The site of the disputed behavior is usually not an acceptable place to discuss moderation decisions, and moderators may move or remove any such discussion.
34-
35-
Project maintainers are held to a higher standard, and project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project’s leadership.
36-
If you disagree with a moderation action, you can appeal to the Core Team (or individual Core Team members) privately.
37-
38-
This policy is adapted from the Contributor Code of Conduct [version 1.4](https://www.contributor-covenant.org/version/1/4/code-of-conduct/).
3+
The code of conduct for this project can be found at https://swift.org/code-of-conduct.

Sources/AWSLambdaEvents/SNS.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ extension SNSEvent.Message: Decodable {
6868
case messageAttributes = "MessageAttributes"
6969
case signatureVersion = "SignatureVersion"
7070
case timestamp = "Timestamp"
71-
case signingCertURL = "SigningCertURL"
71+
case signingCertURL = "SigningCertUrl"
7272
case message = "Message"
73-
case unsubscribeURL = "UnsubscribeURL"
73+
case unsubscribeURL = "UnsubscribeUrl"
7474
case subject = "Subject"
7575
}
7676
}

Sources/AWSLambdaEvents/Utils/HTTP.swift

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,68 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
// MARK: HTTPMethod
15+
// MARK: HTTPHeaders
1616

1717
public typealias HTTPHeaders = [String: String]
1818
public typealias HTTPMultiValueHeaders = [String: [String]]
1919

20+
extension HTTPHeaders {
21+
/// Retrieves the first value for a given header-field / dictionary-key (`name`) from the block.
22+
/// This method uses case-insensitive comparisons.
23+
///
24+
/// - Parameter name: The header field name whose first value should be retrieved.
25+
/// - Returns: The first value for the header field name.
26+
public func first(name: String) -> String? {
27+
guard !self.isEmpty else {
28+
return nil
29+
}
30+
31+
return self.first { header in header.0.isEqualCaseInsensitiveASCIIBytes(to: name) }?.1
32+
}
33+
}
34+
35+
extension String {
36+
internal func isEqualCaseInsensitiveASCIIBytes(to: String) -> Bool {
37+
self.utf8.compareCaseInsensitiveASCIIBytes(to: to.utf8)
38+
}
39+
}
40+
41+
extension String.UTF8View {
42+
/// Compares the collection of `UInt8`s to a case insensitive collection.
43+
///
44+
/// This collection could be get from applying the `UTF8View`
45+
/// property on the string protocol.
46+
///
47+
/// - Parameter bytes: The string constant in the form of a collection of `UInt8`
48+
/// - Returns: Whether the collection contains **EXACTLY** this array or no, but by ignoring case.
49+
internal func compareCaseInsensitiveASCIIBytes(to: String.UTF8View) -> Bool {
50+
// fast path: we can get the underlying bytes of both
51+
let maybeMaybeResult = self.withContiguousStorageIfAvailable { lhsBuffer -> Bool? in
52+
to.withContiguousStorageIfAvailable { rhsBuffer in
53+
if lhsBuffer.count != rhsBuffer.count {
54+
return false
55+
}
56+
57+
for idx in 0 ..< lhsBuffer.count {
58+
// let's hope this gets vectorised ;)
59+
if lhsBuffer[idx] & 0xDF != rhsBuffer[idx] & 0xDF {
60+
return false
61+
}
62+
}
63+
return true
64+
}
65+
}
66+
67+
if let maybeResult = maybeMaybeResult, let result = maybeResult {
68+
return result
69+
} else {
70+
return self.elementsEqual(to, by: { ($0 & 0xDF) == ($1 & 0xDF) })
71+
}
72+
}
73+
}
74+
75+
// MARK: HTTPMethod
76+
2077
public struct HTTPMethod: RawRepresentable, Equatable {
2178
public var rawValue: String
2279

Tests/AWSLambdaEventsTests/SNSTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class SNSTests: XCTestCase {
3232
"Timestamp": "2020-01-08T14:18:51.203Z",
3333
"SignatureVersion": "1",
3434
"Signature": "LJMF/xmMH7A1gNy2unLA3hmzyf6Be+zS/Yeiiz9tZbu6OG8fwvWZeNOcEZardhSiIStc0TF7h9I+4Qz3omCntaEfayzTGmWN8itGkn2mfn/hMFmPbGM8gEUz3+jp1n6p+iqP3XTx92R0LBIFrU3ylOxSo8+SCOjA015M93wfZzwj0WPtynji9iAvvtf15d8JxPUu1T05BRitpFd5s6ZXDHtVQ4x/mUoLUN8lOVp+rs281/ZdYNUG/V5CwlyUDTOERdryTkBJ/GO1NNPa+6m04ywJFa5d+BC8mDcUcHhhXXjpTEbt8AHBmswK3nudHrVMRO/G4zmssxU2P7ii5+gCfA==",
35-
"SigningCertURL": "https://sns.eu-central-1.amazonaws.com/SimpleNotificationService-6aad65c2f9911b05cd53efda11f913f9.pem",
36-
"UnsubscribeURL": "https://sns.eu-central-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-central-1:079477498937:EventSources-SNSTopic-1NHENSE2MQKF5:6fabdb7f-b27e-456d-8e8a-14679db9e40c",
35+
"SigningCertUrl": "https://sns.eu-central-1.amazonaws.com/SimpleNotificationService-6aad65c2f9911b05cd53efda11f913f9.pem",
36+
"UnsubscribeUrl": "https://sns.eu-central-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-central-1:079477498937:EventSources-SNSTopic-1NHENSE2MQKF5:6fabdb7f-b27e-456d-8e8a-14679db9e40c",
3737
"MessageAttributes": {
3838
"binary":{
3939
"Type": "Binary",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftAWSLambdaRuntime open source project
4+
//
5+
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import AWSLambdaEvents
16+
import XCTest
17+
18+
class HTTPHeadersTests: XCTestCase {
19+
func first() throws {
20+
let headers: HTTPHeaders = [
21+
":method": "GET",
22+
"foo": "bar",
23+
"custom-key": "value-1,value-2",
24+
]
25+
26+
XCTAssertEqual(headers.first(name: ":method"), "GET")
27+
XCTAssertEqual(headers.first(name: "Foo"), "bar")
28+
XCTAssertEqual(headers.first(name: "custom-key"), "value-1,value-2")
29+
XCTAssertNil(headers.first(name: "not-present"))
30+
}
31+
}

0 commit comments

Comments
 (0)