When using ProxyConfiguration, use different proxy for HTTP and HTTPS with WKWebView

I am currently developing an app using WKWebView. In iOS 17, Apple introduced ProxyConfiguration, and I have two questions regarding its usage:

  1. Is there a way to use ProxyConfiguration to distinguish between HTTP and HTTPS traffic?

I have reviewed the documentation but couldn’t find a clear method for this. As an alternative approach, I am attempting to determine the request scheme within WKWebView and switch proxyConfigurations just before loading the request. My current implementation sends requests to hoge_a by default and switches to hoge_b only for HTTP traffic.  

if #available(iOS 17.0, *) {
    if URLString.contains("http:") {
        webView.configuration.websiteDataStore.proxyConfigurations = [hoge_b]
    }
}
webView.load(request)
if #available(iOS 17.0, *) {
    if URLString.contains("http:") {
        webView.configuration.websiteDataStore.proxyConfigurations = [hoge_a]
    }
}

  2. Since I modify proxyConfigurations every time webView.load(request) is called, are there any potential issues or concerns with this approach?

I would appreciate any insights you may have on either of these questions.

Written by K0k1 in 774439021
Is there a way to use ProxyConfiguration to distinguish between HTTP and HTTPS traffic?

No.

Written by K0k1 in 774439021
Since I modify proxyConfigurations every time webView.load(request) is called, are there any potential issues or concerns with this approach?

It’s definitely a concern. I can imagine it working reasonably well in some limitation situations but, in general, a website is allowed to issue both HTTP and HTTPS requests. If you start out with, say, HTTP and it redirects to HTTPS, this logic is not going to yield the results you’re looking for.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

When using ProxyConfiguration, use different proxy for HTTP and HTTPS with WKWebView
 
 
Q