Skip to content

Commit

Permalink
Added setting proxy from Client itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
OrkhanAlikhanov committed Jul 14, 2017
1 parent 88d12b7 commit e536c42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Sources/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ open class Client {
let queue = DispatchQueue(label: "com.biatoms.request-swift." + UUID().uuidString)
var firesImmediately: Bool = true
var timeout: Int = 5000 // in ms
var proxy: Proxy? = nil

public init(baseUrl: String? = nil) {
self.baseUrl = baseUrl
Expand All @@ -41,7 +42,7 @@ open class Client {

let request = Request(method: method, url: url, headers: headers ?? [:], body: [])
encoding.encode(request, with: parameters)
let requester = Requester(request: request, queue: queue, timeout: timeout)
let requester = Requester(request: request, queue: queue, timeout: timeout, proxy: proxy)

if firesImmediately {
requester.startAsync()
Expand Down
6 changes: 4 additions & 2 deletions Sources/Requester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import Dispatch
import SocketSwift

public typealias ResponseHandler = (Response?, Error?) -> Void
public typealias Proxy = (host: String, port: SocketSwift.Port)
open class Requester {
open var timeout: Int
open var queue: DispatchQueue
open var request: Request
open var response: Response?
open var error: Error?
open var handler: ResponseHandler? = nil
open var proxy: (host: String, port: SocketSwift.Port)? = nil
open var proxy: Proxy? = nil

public init(request: Request, queue: DispatchQueue, timeout: Int) {
public init(request: Request, queue: DispatchQueue, timeout: Int, proxy: Proxy?) {
self.request = request
self.queue = queue
self.timeout = timeout
self.proxy = proxy
}

open func startAsync() {
Expand Down

0 comments on commit e536c42

Please sign in to comment.