Skip to content

Commit

Permalink
fix: darwin PAC proxy for https:// URL
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
djs55 authored and mattn committed May 22, 2024
1 parent 8fd8dc5 commit d96f056
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions pac_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit d96f056

Please sign in to comment.