@@ -38,22 +38,22 @@ extension Http.Validate.Status: ExpressibleByIntegerLiteral {
3838}
3939
4040 // MARK: - API
41-
41+ @ available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
4242public extension Http . Validate . Status {
4343
4444 /// Validate status
4545 /// - Parameter data: URLResponse
46- func validate( _ data : URLResponse ) throws {
46+ func validate( _ response : URLResponse , with data : Data ? ) throws {
4747
48- guard let status = ( data as? HTTPURLResponse ) ? . statusCode else { return try err ( nil , data) }
48+ guard let status = ( response as? HTTPURLResponse ) ? . statusCode else { return try err ( nil , response , with : data) }
4949
5050 switch ( self ) {
5151 case . const( let value) :
52- if value != status { try err ( status, data) }
52+ if value != status { try err ( status, response , with : data) }
5353 case . range( let value) :
54- if !value. contains ( status) { try err ( status, data) }
54+ if !value. contains ( status) { try err ( status, response , with : data) }
5555 case . predicate( let fn) :
56- if !fn( status) { try err ( status, data) }
56+ if !fn( status) { try err ( status, response , with : data) }
5757 }
5858 }
5959}
@@ -66,9 +66,12 @@ public extension Http.Validate.Status{
6666/// - validate: Set of func to validate status code
6767/// - Throws: Http.Errors.status(response)
6868@available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
69- public func validateStatus( _ response : URLResponse , by rule : Http . Validate . Status ) throws {
70-
71- try rule. validate ( response)
69+ public func validateStatus(
70+ _ response : URLResponse ,
71+ by rule : Http . Validate . Status ,
72+ with data : Data ? = nil
73+ ) throws {
74+ try rule. validate ( response, with: data)
7275}
7376
7477
@@ -78,15 +81,20 @@ public func validateStatus(_ response : URLResponse, by rule : Http.Validate.Sta
7881/// - validate: Set of func to validate status code
7982/// - Throws: Http.Errors.status(response)
8083@available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
81- public func validateStatus( _ response : URLResponse , by rules : [ Http . Validate . Status ] ) throws {
82-
84+ public func validateStatus(
85+ _ response : URLResponse ,
86+ by rules : [ Http . Validate . Status ] ,
87+ with data : Data ? = nil
88+ ) throws {
8389 try rules. forEach {
84- try validateStatus ( response, by: $0)
90+ try validateStatus ( response, by: $0, with : data )
8591 }
8692}
8793
8894// MARK: - File private
8995
90- fileprivate func err( _ status: Int ? , _ response : URLResponse ) throws {
91- throw Http . Errors. status ( status, response)
96+ fileprivate func err(
97+ _ status: Int ? , _ response : URLResponse , with data : Data ?
98+ ) throws {
99+ throw Http . Errors. status ( status, response, data)
92100}
0 commit comments