Go to file
Mikhail Churbanov 3eef3cb2fb
Merge pull request #4 from rinold/develop
Update to version 0.3.1
2018-07-24 22:54:02 +03:00
Example Fixed 'swift test' issues and updated podspec 2018-07-24 22:25:30 +03:00
ProxyResolver Allow changing config after init 2018-07-24 22:49:54 +03:00
.gitignore Updated to work with SPM 2018-06-12 19:02:28 +03:00
.swift-version Updated readme, fixed pod lint warnings 2018-05-31 23:29:01 +03:00
.travis.yml Updated sheme for travis 2018-06-12 18:36:47 +03:00
LICENSE Initial commit 2018-05-21 09:12:57 +03:00
Package.swift Updated to work with SPM 2018-06-12 19:02:28 +03:00
ProxyResolver.podspec Fixed 'swift test' issues and updated podspec 2018-07-24 22:25:30 +03:00
README.md Updated README.md 2018-06-16 14:39:55 +03:00
_Pods.xcodeproj Initial commit 2018-05-21 09:12:57 +03:00

README.md

ProxyResolver

CI Status Swift Version Carthage Carthage License Platform

ProxyResolver allows simply resolve the actual proxy information from users system configuration and could be used for setting up Stream-based connections, for example for Web Sockets.

Usage example:

import ProxyResolver

let proxy = ProxyResolver()
let url = URL(string: "https://github.com")!
proxy.resolve(for: url) { result in
  switch result {
    case .direct:
      // Direct connection allowed - no proxy required
      break
    case .proxy(let proxy):
      // here you can establish connection to proxy or whatever you want
      // proxy.type - one of ProxyType enum: .http, .https or .socks
      // proxy.host - host name of proxy to use
      // proxy.port - port number
      break
    case .error(let error):
      // Handle error
      break
  }
}

Features

Supported system configurations

  • Auto Proxy Discovery*
  • Automatic Proxy Configuration URL*
  • Web Proxy (HTTP)
  • Secure Web Proxy (HTTPS)
  • SOCKS Proxy
  • FTP Proxy
  • Streaming Proxy (RTSP)
  • Gopher Proxy

* due to ATS protection auto-configuration url should be HTTPS or have *.local or unresolvable globally domain, otherwise you will need to set the NSAllowsLocalNetworking key in plist. More info could be found in NSAppTransportSecurity reference.

Other features

  • Proxy with required password support

Proxy.credentials will automatically access Proxy keychain to retrieve configured for proxy account and password. As it would require permission from user the credentials are retrieved lazily only when you try to get them.


  • Configurable

You can use custom proxy configuration provider instead of system one, or provide your own fetcher for downloading auto-configuration scripts instead of default one based on NSURLSession.


  • Aligned with Apple recommendations

"In general, you should try to download a URL using the first proxy in the array, try the second proxy if the first one fails, and so on." - as described in documentation for used CFNetworkCopyProxiesForURL method.

Using the ProxyResolverDelegate you can try connection to resolved proxy and in case of any issue or if your just want to retrieve all - continue resolution if any proxy configuration are still available.

class CustomDelegate: ProxyResolverDelegate {
  func proxyResolver(_ proxyResolver: ProxyResolver, didResolve result: ProxyResolutionResult, for url: URL, resolveNext: ResolveNextRoutine?) {
    switch result {
    case .direct:
      // no proxy required - try to connect to your 'url' directly
      break
    case .proxy(let proxy):
      // try connect to your 'url' using resolved 'proxy'
      yourConnectMethod(to: url, using: proxy) { (response, error) in
        if let error = error {
          // If connection failed we will try to resolve next proxy if
          // available and retry connection
          resolveNext?()
        }
      }
    case .error(let error):
      // handle error
      break
    }
}

  • Documentation

TBD

Requirements

  • Swift: 4+
  • macOS: 10.10+

Installation

CocoaPods

To install it add the following line to Podfile:

pod 'ProxyResolver'

For example:

use_frameworks!

target 'TestPackagesForProxyResolver' do
  platform :osx, '10.12'
  pod 'ProxyResolver'
end

Carthage

To install it add following line to Cartfile:

GitHub "rinold/ProxyResolver"

Swift Package Manager

To install it add following package to needed Packages.swift dependencies:

.package(url: "https://github.com/rinold/ProxyResolver.git", from: "0.3.0")

For example:

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "TestPackagesForProxyResolver",
    products: [
        .executable(name: "TestPackagesForProxyResolver", targets: ["TestPackagesForProxyResolver"]),
    ],
    dependencies: [
        .package(url: "https://github.com/rinold/ProxyResolver.git", from: "0.3.0"),
    ],
    targets: [
        .target(
            name: "TestPackagesForProxyResolver",
            dependencies: ["ProxyResolver.git"]),
    ]
)

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Author

ProxyResolver was initially inspired by the web sockets Starscream proxy support PR.

Mikhail Churbanov, mihail.churbanov@gmail.com

License

ProxyResolver is available under the MIT license. See the LICENSE file for more info.