Created
March 12, 2017 20:02
-
-
Save shnhrrsn/45d9eeb3187dbd1bbee02f697daf68a2 to your computer and use it in GitHub Desktop.
URLSession + MITM Proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate class NetworkingDelegate: NSObject, URLSessionDelegate { | |
fileprivate func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { | |
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!)) | |
} | |
} | |
private let proxySessionDelegate = NetworkingDelegate() | |
private func makeProxySession() -> URLSession { | |
let proxyPort = 8080 | |
let proxyHost = "10.0.1.88" | |
let configuration = URLSessionConfiguration.default | |
configuration.connectionProxyDictionary = [ | |
"HTTPEnable": true, | |
"HTTPProxy": proxyHost, | |
"HTTPPort": proxyPort, | |
"HTTPSEnable": true, | |
"HTTPSProxy": proxyHost, | |
"HTTPSPort": proxyPort, | |
] | |
return URLSession(configuration: configuration, delegate: proxySessionDelegate, delegateQueue: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment