Skip to content
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
2 changes: 2 additions & 0 deletions Sources/AWSLambdaEvents/APIGateway+WebSockets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ public struct APIGatewayWebSocketRequest: Codable {
}

public let headers: HTTPHeaders?
public let queryStringParameters: [String: String]?
public let multiValueHeaders: HTTPMultiValueHeaders?
public let context: Context
public let body: String?
public let isBase64Encoded: Bool?

enum CodingKeys: String, CodingKey {
case headers
case queryStringParameters
case multiValueHeaders
case context = "requestContext"
case body
Expand Down
55 changes: 55 additions & 0 deletions Tests/AWSLambdaEventsTests/APIGateway+WebsocketsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,54 @@ class APIGatewayWebSocketsTests {
}
"""

static let exampleConnectEventBodyWithQueryParams = """
{
"headers": {
"Host": "lqrlmblaa2.execute-api.us-east-1.amazonaws.com",
"Origin": "wss://lqrlmblaa2.execute-api.us-east-1.amazonaws.com",
"Sec-WebSocket-Extensions": "",
"Sec-WebSocket-Key": "am5ubWVpbHd3bmNyYXF0ag==",
"Sec-WebSocket-Version": "13",
"X-Amzn-Trace-Id": "Root=1-64b83950-42de8e247b4c2b43091ef67c",
"X-Forwarded-For": "24.148.42.16",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"queryStringParameters":{
"foo":"bar"
},
"multiValueHeaders": {
"Host": [ "lqrlmblaa2.execute-api.us-east-1.amazonaws.com" ],
"Origin": [ "wss://lqrlmblaa2.execute-api.us-east-1.amazonaws.com" ],
"Sec-WebSocket-Extensions": [
"permessage-deflate; client_max_window_bits; server_max_window_bits=15"
],
"Sec-WebSocket-Key": [ "am5ubWVpbHd3bmNyYXF0ag==" ],
"Sec-WebSocket-Version": [ "13" ],
"X-Amzn-Trace-Id": [ "Root=1-64b83950-42de8e247b4c2b43091ef67c" ],
"X-Forwarded-For": [ "24.148.42.16" ],
"X-Forwarded-Port": [ "443" ],
"X-Forwarded-Proto": [ "https" ]
},
"requestContext": {
"routeKey": "$connect",
"eventType": "CONNECT",
"extendedRequestId": "IU3kkGyEoAMFwZQ=",
"requestTime": "19/Jul/2023:19:28:16 +0000",
"messageDirection": "IN",
"stage": "dev",
"connectedAt": 1689794896145,
"requestTimeEpoch": 1689794896162,
"identity": { "sourceIp": "24.148.42.16" },
"requestId": "IU3kkGyEoAMFwZQ=",
"domainName": "lqrlmblaa2.execute-api.us-east-1.amazonaws.com",
"connectionId": "IU3kkeN4IAMCJwA=",
"apiId": "lqrlmblaa2"
},
"isBase64Encoded": false
}
"""

// MARK: - Request -

// MARK: Decoding
Expand All @@ -76,4 +124,11 @@ class APIGatewayWebSocketsTests {
#expect(req.context.connectionId == "IU3kkeN4IAMCJwA=")
#expect(req.body == nil)
}

@Test func testRequestDecodingExampleWithQueryParams() async throws {
let data = APIGatewayWebSocketsTests.exampleConnectEventBodyWithQueryParams.data(using: .utf8)!
let req = try JSONDecoder().decode(APIGatewayWebSocketRequest.self, from: data)

#expect(req.queryStringParameters?["foo"] == "bar")
}
}