@@ -22,22 +22,45 @@ import NIO
2222import NIOHTTP1
2323import NIOFoundationCompat
2424
25+ /**
26+ `SprinterNIO` implements the AWS Lambda Custom Runtime with `SwiftNIO`
27+ */
2528public typealias SprinterNIO = Sprinter < LambdaApiNIO >
2629
30+
31+ /**
32+ SprinterNIOError
33+ An error related to the `SprinterNIO`
34+
35+ ### Errors: ###
36+ ```
37+ case invalidResponse(HTTPResponseStatus)
38+ case invalidBuffer
39+ ```
40+ */
2741public enum SprinterNIOError : Error {
42+
43+ /// Invalid Reponse with `HTTPResponseStatus`
2844 case invalidResponse( HTTPResponseStatus )
45+
46+ /// Invalid Buffer
2947 case invalidBuffer
3048}
3149
50+ /** The amount of time the lambda waits for the next event.
51+
52+ The `default` timeout for a Lambda is `3600` seconds.
53+ */
3254public var lambdaRuntimeTimeout : TimeAmount = . seconds( 3600 )
55+
56+ /// The timeout used to create the instance of the `httpClient`
3357public var timeout = HTTPClient . Configuration. Timeout ( connect: lambdaRuntimeTimeout,
3458 read: lambdaRuntimeTimeout)
3559
36- public var httpClient : HTTPClientProtocol = {
37- let configuration = HTTPClient . Configuration ( timeout: timeout)
38- return HTTPClient ( eventLoopGroupProvider: . createNew, configuration: configuration)
39- } ( )
40-
60+ /** The HTTPClientProtocol defines a generic httpClient
61+
62+ Required for Unit Testing
63+ */
4164public protocol HTTPClientProtocol : class {
4265 var eventLoopGroup : EventLoopGroup { get }
4366 func get( url: String , deadline: NIODeadline ? ) -> EventLoopFuture < HTTPClient . Response >
@@ -46,6 +69,16 @@ public protocol HTTPClientProtocol: class {
4669 func syncShutdown( ) throws
4770}
4871
72+
73+ /** The httpClient implementing `HTTPClientProtocol`
74+
75+ The `default` implementation is an `HTTPClient` defined in `AsyncHTTPClient`
76+ */
77+ public var httpClient : HTTPClientProtocol = {
78+ let configuration = HTTPClient . Configuration ( timeout: timeout)
79+ return HTTPClient ( eventLoopGroupProvider: . createNew, configuration: configuration)
80+ } ( )
81+
4982extension HTTPClient : HTTPClientProtocol {
5083
5184}
0 commit comments