Skip to content

Commit

Permalink
Merge pull request #38 from ragzy15/hotfix/validate
Browse files Browse the repository at this point in the history
Hotfix/validate
  • Loading branch information
ragzy15 committed Apr 19, 2020
2 parents 43344f2 + 001d93a commit 0abfe5f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion PublisherKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

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

spec.homepage = "https://github.com/ragzy15/PublisherKit"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let package = Package(
targets: ["YourPackage"]),
],
dependencies: [
.package(url: "https://github.com/ragzy15/PublisherKit.git", from: "4.0.1"),
.package(url: "https://github.com/ragzy15/PublisherKit.git", from: "4.0.2"),
],
targets: [
.target(
Expand Down Expand Up @@ -80,7 +80,7 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

pod 'PublisherKit', '~> 4.0.1'
pod 'PublisherKit', '~> 4.0.2'
```

Then, run the following command:
Expand Down
6 changes: 6 additions & 0 deletions Sources/PublisherKit/Error/URLError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ extension URLError {
NSLocalizedDescriptionKey: "Content data received during a connection request had an unknown content encoding."
])
}

static func onlyHTTPSupported() -> Error {
URLError(.cannotParseResponse, userInfo: [
NSLocalizedDescriptionKey: "Currently Validate only works on HTTP requests."
])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ extension Publisher {
}

// MARK: VALIDATE
extension Publisher where Output == (data: Data, response: HTTPURLResponse) {
extension Publisher where Output == (data: Data, response: URLResponse) {

/// 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.
///
Expand Down
4 changes: 2 additions & 2 deletions Sources/PublisherKit/Publishers/URLSession/Data Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension URLSession {

public struct DataTaskPKPublisher: PublisherKit.Publisher {

public typealias Output = (data: Data, response: HTTPURLResponse)
public typealias Output = (data: Data, response: URLResponse)

public typealias Failure = Error

Expand Down Expand Up @@ -104,7 +104,7 @@ extension URLSession.DataTaskPKPublisher {

if let error = error {
downstream.receive(completion: .failure(error))
} else if let response = response as? HTTPURLResponse, let data = data {
} else if let response = response, let data = data {
_ = downstream.receive((data, response))
downstream.receive(completion: .finished)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension URLSession {

public struct DownloadTaskPKPublisher: PublisherKit.Publisher {

public typealias Output = (url: URL, response: HTTPURLResponse)
public typealias Output = (url: URL, response: URLResponse)

public typealias Failure = Error

Expand Down Expand Up @@ -129,7 +129,7 @@ extension URLSession.DownloadTaskPKPublisher {

if let error = error {
downstream.receive(completion: .failure(error))
} else if let url = url, let response = response as? HTTPURLResponse {
} else if let url = url, let response = response {
_ = downstream.receive((url, response))
downstream.receive(completion: .finished)
} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/PublisherKit/Publishers/URLSession/Upload Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension URLSession {

public struct UploadTaskPKPublisher: PublisherKit.Publisher {

public typealias Output = (data: Data, response: HTTPURLResponse)
public typealias Output = (data: Data, response: URLResponse)

public typealias Failure = Error

Expand Down Expand Up @@ -124,7 +124,7 @@ extension URLSession.UploadTaskPKPublisher {

if let error = error {
downstream.receive(completion: .failure(error))
} else if let response = response as? HTTPURLResponse, let data = data {
} else if let response = response, let data = data {
_ = downstream.receive((data, response))
downstream.receive(completion: .finished)
} else {
Expand Down
10 changes: 7 additions & 3 deletions Sources/PublisherKit/Publishers/URLSession/Validate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public enum AcceptableContentTypes {

extension Publishers {

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

public typealias Output = Upstream.Output
public typealias Output = (data: Data, response: HTTPURLResponse)

public typealias Failure = Error

Expand Down Expand Up @@ -159,7 +159,11 @@ private extension Publishers.Validate.Inner {

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

let (data, response) = input
let (data, _response) = input

guard let response = _response as? HTTPURLResponse else {
return .failure(URLError.onlyHTTPSupported())
}

guard acceptableStatusCodes.contains(response.statusCode) else {

Expand Down

0 comments on commit 0abfe5f

Please sign in to comment.