|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the SwiftAWSLambdaRuntime open source project |
| 4 | +// |
| 5 | +// Copyright (c) YEARS 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 | +/// `APIGatewayWebSocketRequest` is a variation of the`APIGatewayV2Request` |
| 16 | +/// and contains data coming from the WebSockets API Gateway. |
| 17 | +public struct APIGatewayWebSocketRequest: Codable { |
| 18 | + /// `Context` contains information to identify the AWS account and resources invoking the Lambda function. |
| 19 | + public struct Context: Codable { |
| 20 | + public struct Identity: Codable { |
| 21 | + public let sourceIp: String |
| 22 | + } |
| 23 | + |
| 24 | + public let routeKey: String |
| 25 | + public let eventType: String |
| 26 | + public let extendedRequestId: String |
| 27 | + /// The request time in format: 23/Apr/2020:11:08:18 +0000 |
| 28 | + public let requestTime: String |
| 29 | + public let messageDirection: String |
| 30 | + public let stage: String |
| 31 | + public let connectedAt: UInt64 |
| 32 | + public let requestTimeEpoch: UInt64 |
| 33 | + public let identity: Identity |
| 34 | + public let requestId: String |
| 35 | + public let domainName: String |
| 36 | + public let connectionId: String |
| 37 | + public let apiId: String |
| 38 | + } |
| 39 | + |
| 40 | + public let headers: HTTPHeaders? |
| 41 | + public let multiValueHeaders: HTTPMultiValueHeaders? |
| 42 | + public let context: Context |
| 43 | + public let body: String? |
| 44 | + public let isBase64Encoded: Bool? |
| 45 | + |
| 46 | + enum CodingKeys: String, CodingKey { |
| 47 | + case headers |
| 48 | + case multiValueHeaders |
| 49 | + case context = "requestContext" |
| 50 | + case body |
| 51 | + case isBase64Encoded |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +/// `APIGatewayWebSocketResponse` is a type alias for `APIGatewayV2Request`. |
| 56 | +/// Typically, lambda WebSockets servers send clients data via |
| 57 | +/// the ApiGatewayManagementApi mechanism. However, APIGateway does require |
| 58 | +/// lambda servers to return some kind of status when APIGateway invokes them. |
| 59 | +/// This can be as simple as always returning a 200 "OK" response for all |
| 60 | +/// WebSockets requests (the ApiGatewayManagementApi can return any errors to |
| 61 | +/// WebSockets clients). |
| 62 | +public typealias APIGatewayWebSocketResponse = APIGatewayV2Response |
| 63 | + |
| 64 | +#if swift(>=5.6) |
| 65 | +extension APIGatewayWebSocketRequest: Sendable {} |
| 66 | +extension APIGatewayWebSocketRequest.Context: Sendable {} |
| 67 | +extension APIGatewayWebSocketRequest.Context.Identity: Sendable {} |
| 68 | +#endif |
0 commit comments