File tree Expand file tree Collapse file tree 7 files changed +49
-23
lines changed Expand file tree Collapse file tree 7 files changed +49
-23
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ Resources:
6363 SecurityGroups :
6464 - !Ref ALBSecurityGroup
6565
66- # Listener
66+ # HTTP Listener (HTTPS requires valid domain certificate)
6767 ALBListener :
6868 Type : AWS::ElasticLoadBalancingV2::Listener
6969 Properties :
Original file line number Diff line number Diff line change 1+ format :
2+ @swift format -i -r Package.swift Examples Sources
Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ extension ALBTargetGroupRequest {
2222 public func httpRequest( ) throws -> HTTPRequest {
2323 HTTPRequest (
2424 method: self . httpMethod,
25- scheme: nil ,
26- authority: nil ,
25+ scheme: self . headers ? [ " X-Forwarded-Proto " ] ,
26+ authority: self . headers ? [ " Host " ] ,
2727 path: self . path,
2828 headerFields: self . headers? . httpFields ( ) ?? [ : ]
2929 )
@@ -32,7 +32,7 @@ extension ALBTargetGroupRequest {
3232
3333extension ALBTargetGroupResponse {
3434
35- /// Create a `APIGatewayV2Response ` from an `HTTPResponse`
35+ /// Create an `ALBTargetGroupResponse ` from an `HTTPResponse`
3636 public init ( from response: HTTPResponse ) {
3737 self = ALBTargetGroupResponse (
3838 statusCode: response. status,
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import AWSLambdaEvents
1818import OpenAPIRuntime
1919import HTTPTypes
2020
21- /// An specialization of the `OpenAPILambda` protocol that works with Amazon API Gateway HTTP Mode, aka API Gateway v2
21+ /// An specialization of the `OpenAPILambda` protocol that works with an Application Load Balancer
2222public protocol OpenAPILambdaALB : OpenAPILambdaService
2323where
2424 Event == ALBTargetGroupRequest ,
@@ -27,12 +27,12 @@ where
2727
2828
2929extension OpenAPILambdaALB {
30- /// Transform a Lambda input (`APIGatewayV2Request ` and `LambdaContext`) to an OpenAPILambdaRequest (`HTTPRequest`, `String?`)
30+ /// Transform a Lambda input (`ALBTargetGroupRequest ` and `LambdaContext`) to an OpenAPILambdaRequest (`HTTPRequest`, `String?`)
3131 public func request( context: LambdaContext , from request: Event ) throws -> OpenAPILambdaRequest {
3232 ( try request. httpRequest ( ) , request. body)
3333 }
3434
35- /// Transform an OpenAPI response (`HTTPResponse`, `String?`) to a Lambda Output (`APIGatewayV2Response `)
35+ /// Transform an OpenAPI response (`HTTPResponse`, `String?`) to a Lambda Output (`ALBTargetGroupResponse `)
3636 public func output( from response: OpenAPILambdaResponse ) -> Output {
3737 var apiResponse = ALBTargetGroupResponse ( from: response. 0 )
3838 apiResponse. body = response. 1 ?? " "
Original file line number Diff line number Diff line change 1+ //===----------------------------------------------------------------------===//
2+ //
3+ // This source file is part of the Swift OpenAPI Lambda open source project
4+ //
5+ // Copyright Swift OpenAPI Lambda project authors
6+ // Copyright (c) 2023 Amazon.com, Inc. or its affiliates.
7+ // Licensed under Apache License v2.0
8+ //
9+ // See LICENSE.txt for license information
10+ // See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors
11+ //
12+ // SPDX-License-Identifier: Apache-2.0
13+ //
14+ //===----------------------------------------------------------------------===//
15+ import AWSLambdaEvents
16+ import HTTPTypes
17+
18+ public extension HTTPHeaders {
19+ /// Create an `HTTPFields` (from `HTTPTypes` library) from this APIGateway `HTTPHeader`
20+ func httpFields( ) -> HTTPFields {
21+ HTTPFields ( self . map { key, value in HTTPField ( name: . init( key) !, value: value) } )
22+ }
23+
24+ /// Create HTTPHeaders from HTTPFields
25+ init ( from fields: HTTPFields ) {
26+ var headers : HTTPHeaders = [ : ]
27+ for field in fields {
28+ let name = field. name. rawName
29+ if let existing = headers [ name] {
30+ headers [ name] = " \( existing) , \( field. value) "
31+ }
32+ else {
33+ headers [ name] = field. value
34+ }
35+ }
36+ self = headers
37+ }
38+ }
Original file line number Diff line number Diff line change @@ -27,8 +27,8 @@ extension APIGatewayV2Request {
2727 public func httpRequest( ) throws -> HTTPRequest {
2828 HTTPRequest (
2929 method: self . context. http. method,
30- scheme: " https " ,
31- authority: " " ,
30+ scheme: " https " , // APIGateway is always HTTPS
31+ authority: self . headers [ " Host " ] ,
3232 path: pathWithQueryString,
3333 headerFields: self . headers. httpFields ( )
3434 )
@@ -47,17 +47,3 @@ extension APIGatewayV2Response {
4747 )
4848 }
4949}
50-
51- public extension HTTPHeaders {
52- /// Create an `HTTPFields` (from `HTTPTypes` library) from this APIGateway `HTTPHeader`
53- func httpFields( ) -> HTTPFields {
54- HTTPFields ( self . map { key, value in HTTPField ( name: . init( key) !, value: value) } )
55- }
56-
57- /// Create HTTPHeaders from HTTPFields
58- init ( from fields: HTTPFields ) {
59- var headers : HTTPHeaders = [ : ]
60- fields. forEach { headers [ $0. name. rawName] = $0. value }
61- self = headers
62- }
63- }
File renamed without changes.
You can’t perform that action at this time.
0 commit comments