Skip to content

Commit

Permalink
Add customizable session delegate.
Browse files Browse the repository at this point in the history
  • Loading branch information
janmisar committed Aug 2, 2018
1 parent cc5183b commit 1c3b1b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Reqres.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Reqres'
s.version = '2.1.1'
s.version = '2.2.0'
s.summary = 'Simple network activity logger'

s.description = <<-DESC
Expand Down
4 changes: 3 additions & 1 deletion Reqres/Reqres.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ open class Reqres: URLProtocol, URLSessionDelegate {
var dataTask: URLSessionDataTask?
var newRequest: NSMutableURLRequest?

open static var sessionDelegate: URLSessionDelegate?

open static var allowUTF8Emoji: Bool = true

open static var logger: ReqresLogging = ReqresDefaultLogger()
Expand Down Expand Up @@ -58,7 +60,7 @@ open class Reqres: URLProtocol, URLSessionDelegate {
URLProtocol.setProperty(true, forKey: ReqresRequestHandledKey, in: newRequest!)
URLProtocol.setProperty(Date(), forKey: ReqresRequestTimeKey, in: newRequest!)

let session = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
let session = URLSession(configuration: .default, delegate: Reqres.sessionDelegate ?? self, delegateQueue: nil)
dataTask = session.dataTask(with: request) { [weak self] data, response, error in
guard let `self` = self else { return }

Expand Down

0 comments on commit 1c3b1b5

Please sign in to comment.