Skip to content

Commit 0abfe5f

Browse files
authored
Merge pull request #38 from ragzy15/hotfix/validate
Hotfix/validate
2 parents 43344f2 + 001d93a commit 0abfe5f

File tree

8 files changed

+23
-13
lines changed

8 files changed

+23
-13
lines changed

PublisherKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |spec|
22

33
spec.name = "PublisherKit"
4-
spec.version = "4.0.1"
4+
spec.version = "4.0.2"
55
spec.summary = "An open source implementation of Apple's Combine framework for processing asynchronous events over time"
66

77
spec.homepage = "https://github.com/ragzy15/PublisherKit"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let package = Package(
5151
targets: ["YourPackage"]),
5252
],
5353
dependencies: [
54-
.package(url: "https://github.com/ragzy15/PublisherKit.git", from: "4.0.1"),
54+
.package(url: "https://github.com/ragzy15/PublisherKit.git", from: "4.0.2"),
5555
],
5656
targets: [
5757
.target(
@@ -80,7 +80,7 @@ source 'https://github.com/CocoaPods/Specs.git'
8080
platform :ios, '10.0'
8181
use_frameworks!
8282

83-
pod 'PublisherKit', '~> 4.0.1'
83+
pod 'PublisherKit', '~> 4.0.2'
8484
```
8585

8686
Then, run the following command:

Sources/PublisherKit/Error/URLError.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ extension URLError {
2020
NSLocalizedDescriptionKey: "Content data received during a connection request had an unknown content encoding."
2121
])
2222
}
23+
24+
static func onlyHTTPSupported() -> Error {
25+
URLError(.cannotParseResponse, userInfo: [
26+
NSLocalizedDescriptionKey: "Currently Validate only works on HTTP requests."
27+
])
28+
}
2329
}

Sources/PublisherKit/Protocols/Publisher/Publisher+Operators.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ extension Publisher {
12601260
}
12611261

12621262
// MARK: VALIDATE
1263-
extension Publisher where Output == (data: Data, response: HTTPURLResponse) {
1263+
extension Publisher where Output == (data: Data, response: URLResponse) {
12641264

12651265
/// Validates that the response has a status code acceptable in the specified range, and that the response has a content type in the specified sequence.
12661266
///

Sources/PublisherKit/Publishers/URLSession/Data Task.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension URLSession {
3939

4040
public struct DataTaskPKPublisher: PublisherKit.Publisher {
4141

42-
public typealias Output = (data: Data, response: HTTPURLResponse)
42+
public typealias Output = (data: Data, response: URLResponse)
4343

4444
public typealias Failure = Error
4545

@@ -104,7 +104,7 @@ extension URLSession.DataTaskPKPublisher {
104104

105105
if let error = error {
106106
downstream.receive(completion: .failure(error))
107-
} else if let response = response as? HTTPURLResponse, let data = data {
107+
} else if let response = response, let data = data {
108108
_ = downstream.receive((data, response))
109109
downstream.receive(completion: .finished)
110110
} else {

Sources/PublisherKit/Publishers/URLSession/Download Task.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension URLSession {
4949

5050
public struct DownloadTaskPKPublisher: PublisherKit.Publisher {
5151

52-
public typealias Output = (url: URL, response: HTTPURLResponse)
52+
public typealias Output = (url: URL, response: URLResponse)
5353

5454
public typealias Failure = Error
5555

@@ -129,7 +129,7 @@ extension URLSession.DownloadTaskPKPublisher {
129129

130130
if let error = error {
131131
downstream.receive(completion: .failure(error))
132-
} else if let url = url, let response = response as? HTTPURLResponse {
132+
} else if let url = url, let response = response {
133133
_ = downstream.receive((url, response))
134134
downstream.receive(completion: .finished)
135135
} else {

Sources/PublisherKit/Publishers/URLSession/Upload Task.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension URLSession {
4040

4141
public struct UploadTaskPKPublisher: PublisherKit.Publisher {
4242

43-
public typealias Output = (data: Data, response: HTTPURLResponse)
43+
public typealias Output = (data: Data, response: URLResponse)
4444

4545
public typealias Failure = Error
4646

@@ -124,7 +124,7 @@ extension URLSession.UploadTaskPKPublisher {
124124

125125
if let error = error {
126126
downstream.receive(completion: .failure(error))
127-
} else if let response = response as? HTTPURLResponse, let data = data {
127+
} else if let response = response, let data = data {
128128
_ = downstream.receive((data, response))
129129
downstream.receive(completion: .finished)
130130
} else {

Sources/PublisherKit/Publishers/URLSession/Validate.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public enum AcceptableContentTypes {
1818

1919
extension Publishers {
2020

21-
public struct Validate<Upstream: Publisher>: Publisher where Upstream.Output == (data: Data, response: HTTPURLResponse) {
21+
public struct Validate<Upstream: Publisher>: Publisher where Upstream.Output == (data: Data, response: URLResponse) {
2222

23-
public typealias Output = Upstream.Output
23+
public typealias Output = (data: Data, response: HTTPURLResponse)
2424

2525
public typealias Failure = Error
2626

@@ -159,7 +159,11 @@ private extension Publishers.Validate.Inner {
159159

160160
func validate(input: Input) -> Result<Downstream.Input, Downstream.Failure> {
161161

162-
let (data, response) = input
162+
let (data, _response) = input
163+
164+
guard let response = _response as? HTTPURLResponse else {
165+
return .failure(URLError.onlyHTTPSupported())
166+
}
163167

164168
guard acceptableStatusCodes.contains(response.statusCode) else {
165169

0 commit comments

Comments
 (0)