From d96f0566927a1f273bb402e19d061a059c7070f2 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 13 Dec 2022 16:20:55 +0000 Subject: [PATCH] fix: darwin PAC proxy for https:// URL For a URL https://www.google.com and a PAC file which returns `PROXY host:port`, Darwin will return a proxy type of `kCFProxyTypeHTTPS` which the header defines as ``` kCFProxyTypeHTTPS - the proxy is a tunneling proxy as used for HTTPS ``` i.e. it will tunnel the https through `HTTP CONNECT` --- darwin_test.go | 5 +++++ pac_darwin.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/darwin_test.go b/darwin_test.go index 1776ae9..ac69a4c 100644 --- a/darwin_test.go +++ b/darwin_test.go @@ -47,6 +47,11 @@ func TestPacfile(t *testing.T) { "http://google.com", "127.0.0.1:8", }, + { + serverBase + "simple.pac", + "https://google.com", + "127.0.0.1:8", + }, { serverBase + "multiple.pac", "http://google.com", diff --git a/pac_darwin.go b/pac_darwin.go index a8bf90e..6c993f3 100644 --- a/pac_darwin.go +++ b/pac_darwin.go @@ -64,6 +64,20 @@ char* _getProxyUrlFromPac(char* pac, char* reqCs) { CFNumberGetValue(port, kCFNumberIntType, &port_int); } + sprintf(retCString, "%s:%d", host_str, port_int); + } + if (CFEqual(pxyType, kCFProxyTypeHTTPS)) { + CFStringRef host = (CFStringRef)CFDictionaryGetValue(pxy, kCFProxyHostNameKey); + CFNumberRef port = (CFNumberRef)CFDictionaryGetValue(pxy, kCFProxyPortNumberKey); + + char host_str[STR_LEN - 16]; + CFStringGetCString(host, host_str, STR_LEN - 16, kCFStringEncodingUTF8); + + int port_int = 443; + if (port) { + CFNumberGetValue(port, kCFNumberIntType, &port_int); + } + sprintf(retCString, "%s:%d", host_str, port_int); } }