@@ -13,9 +13,9 @@ public struct SessionConfig {
1313
1414 public let secret : String
1515
16- public let expires : Int ?
16+ public let expiration : Int ?
1717
18- public let HTTPOnly : Bool
18+ public let httpOnly : Bool
1919
2020 public let secure : Bool
2121
@@ -25,12 +25,12 @@ public struct SessionConfig {
2525
2626 public let path : String ?
2727
28- public init ( keyName: String = " slimane_sesid " , secret: String , expires : Int ? = nil , HTTPOnly : Bool = false , maxAge: Int ? = nil , domain: String ? = nil , path: String ? = nil , secure: Bool = false , store: SessionStoreType = SessionMemoryStore ( ) ) {
28+ public init ( keyName: String = " slimane_sesid " , secret: String , expiration : Int ? = nil , httpOnly : Bool = false , maxAge: Int ? = nil , domain: String ? = nil , path: String ? = " / " , secure: Bool = false , store: SessionStoreType = SessionMemoryStore ( ) ) {
2929 self . keyName = keyName
3030 self . secret = secret
3131 self . store = store
32- self . expires = expires
33- self . HTTPOnly = HTTPOnly
32+ self . expiration = expiration
33+ self . httpOnly = httpOnly
3434 self . secure = secure
3535 self . maxAge = maxAge
3636 self . domain = domain
@@ -40,77 +40,79 @@ public struct SessionConfig {
4040
4141public struct Session {
4242
43- private var conf : SessionConfig
43+ private var config : SessionConfig
4444
4545 public internal( set) var id : String ? = nil
4646
4747 var values = [ String: String] ( ) {
4848 didSet {
4949 if let id = self . id {
5050 // Need to emit string error
51- self . conf . store. store ( id, values: values, expires : ttl) { _ in }
51+ self . config . store. store ( id, values: values, expiration : ttl) { _ in }
5252 }
5353 }
5454 }
5555
56- init ( conf : SessionConfig ) {
57- self . conf = conf
56+ init ( config : SessionConfig ) {
57+ self . config = config
5858 }
5959
6060 public var keyName : String {
61- return self . conf . keyName
61+ return self . config . keyName
6262 }
6363
6464 public var secret : String {
65- return self . conf . secret
65+ return self . config . secret
6666 }
6767
68- public var HTTPOnly : Bool {
69- return self . conf . HTTPOnly
68+ public var httpOnly : Bool {
69+ return self . config . httpOnly
7070 }
7171
7272 public var secure : Bool {
73- return self . conf . secure
73+ return self . config . secure
7474 }
7575
7676 public var maxAge : Int ? {
77- return self . conf . maxAge
77+ return self . config . maxAge
7878 }
7979
8080 public var domain : String ? {
81- return self . conf . domain
81+ return self . config . domain
8282 }
8383
8484 public var path : String ? {
85- return self . conf . path
85+ return self . config . path
8686 }
8787
88- public var expires : Time ? {
88+ public var expiration : Time ? {
8989 if let ttl = self . ttl {
9090 return Time ( tz: . Local) . addSec ( ttl)
9191 }
9292 return nil
9393 }
9494
9595 public var ttl : Int ? {
96- return self . conf . expires
96+ return self . config . expiration
9797 }
9898
9999 public var hashValue : Int {
100- return self . conf . keyName. hashValue
100+ return self . config . keyName. hashValue
101101 }
102102
103- public func load( _ completion: ( SessionResult < [ String : String ] > ) -> Void ) {
103+ public func load( _ completion: @escaping ( ( Void ) throws -> [ String : String ] ) -> Void ) {
104104 if let id = self . id {
105- self . conf . store. load ( id, completion: completion)
105+ self . config . store. load ( id, completion: completion)
106106 } else {
107- completion ( . error( Error . noSessionID) )
107+ completion {
108+ throw SessionError . noSessionID
109+ }
108110 }
109111 }
110112
111113 public func destroy( ) {
112114 if let id = self . id {
113- self . conf . store. destroy ( id)
115+ self . config . store. destroy ( id)
114116 }
115117 }
116118
@@ -121,15 +123,9 @@ public struct Session {
121123
122124extension Session : Sequence {
123125
124- #if swift(>=3.0)
125126 public func makeIterator( ) -> DictionaryIterator < String , String > {
126127 return values. makeIterator ( )
127128 }
128- #else
129- public func generate( ) -> DictionaryGenerator < String , String > {
130- return values. generate ( )
131- }
132- #endif
133129
134130 public var count : Int {
135131 return values. count
@@ -152,4 +148,4 @@ extension Session: Sequence {
152148 self . values [ key] = newValue
153149 }
154150 }
155- }
151+ }
0 commit comments