-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathAPIGateway+V2.swift
117 lines (100 loc) · 3.6 KB
/
APIGateway+V2.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftAWSLambdaRuntime open source project
//
// Copyright (c) 2017-2022 Apple Inc. and the SwiftAWSLambdaRuntime project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/// `APIGatewayV2Request` contains data coming from the new HTTP API Gateway.
public struct APIGatewayV2Request: Codable {
/// `Context` contains information to identify the AWS account and resources invoking the Lambda function.
public struct Context: Codable {
public struct HTTP: Codable {
public let method: HTTPMethod
public let path: String
public let `protocol`: String
public let sourceIp: String
public let userAgent: String
}
/// `Authorizer` contains authorizer information for the request context.
public struct Authorizer: Codable {
/// `JWT` contains JWT authorizer information for the request context.
public struct JWT: Codable {
public let claims: [String: String]?
public let scopes: [String]?
}
public let jwt: JWT
}
public let accountId: String
public let apiId: String
public let domainName: String
public let domainPrefix: String
public let stage: String
public let requestId: String
public let http: HTTP
public let authorizer: Authorizer?
/// The request time in format: 23/Apr/2020:11:08:18 +0000
public let time: String
public let timeEpoch: UInt64
}
public let version: String
public let routeKey: String
public let rawPath: String
public let rawQueryString: String
public let cookies: [String]?
public let headers: HTTPHeaders
public let queryStringParameters: [String: String]?
public let pathParameters: [String: String]?
public let context: Context
public let stageVariables: [String: String]?
public let body: String?
public let isBase64Encoded: Bool
enum CodingKeys: String, CodingKey {
case version
case routeKey
case rawPath
case rawQueryString
case cookies
case headers
case queryStringParameters
case pathParameters
case context = "requestContext"
case stageVariables
case body
case isBase64Encoded
}
}
public struct APIGatewayV2Response: Codable {
public var statusCode: HTTPResponseStatus
public var headers: HTTPHeaders?
public var body: String?
public var isBase64Encoded: Bool?
public var cookies: [String]?
public init(
statusCode: HTTPResponseStatus,
headers: HTTPHeaders? = nil,
body: String? = nil,
isBase64Encoded: Bool? = nil,
cookies: [String]? = nil
) {
self.statusCode = statusCode
self.headers = headers
self.body = body
self.isBase64Encoded = isBase64Encoded
self.cookies = cookies
}
}
#if swift(>=5.6)
extension APIGatewayV2Request: Sendable {}
extension APIGatewayV2Request.Context: Sendable {}
extension APIGatewayV2Request.Context.HTTP: Sendable {}
extension APIGatewayV2Request.Context.Authorizer: Sendable {}
extension APIGatewayV2Request.Context.Authorizer.JWT: Sendable {}
extension APIGatewayV2Response: Sendable {}
#endif