debian-forge-composer/vendor/github.com/mattn/go-ieproxy/pac_windows.go
Lars Karlitski 6703055925 go: include vendored modules
RHEL requires the source code for dependencies to be included in the
srpm. The spec file already expects that, but we've only included the
vendored modules (i.e., the `vendor` directory) in the `rhel-8.2.`
branch. Move vendoring to master, so that we can build RHEL packages
from it as well.

This commit is the result of running `go mod vendor`, which includes the
vendored sources and updates go.mod and go.sum files.

Fedora requires the opposite: dependencies should not be vendored. The
spec file already ignores the `vendor` directory by default.
2020-02-17 16:09:17 +01:00

72 lines
2 KiB
Go

package ieproxy
import (
"strings"
"syscall"
"unsafe"
)
func (psc *ProxyScriptConf) findProxyForURL(URL string) string {
if !psc.Active {
return ""
}
proxy, _ := getProxyForURL(psc.PreConfiguredURL, URL)
i := strings.Index(proxy, ";")
if i >= 0 {
return proxy[:i]
}
return proxy
}
func getProxyForURL(pacfileURL, URL string) (string, error) {
pacfileURLPtr, err := syscall.UTF16PtrFromString(pacfileURL)
if err != nil {
return "", err
}
URLPtr, err := syscall.UTF16PtrFromString(URL)
if err != nil {
return "", err
}
handle, _, err := winHttpOpen.Call(0, 0, 0, 0, 0)
if handle == 0 {
return "", err
}
defer winHttpCloseHandle.Call(handle)
dwFlags := fWINHTTP_AUTOPROXY_CONFIG_URL
dwAutoDetectFlags := autoDetectFlag(0)
pfURLptr := pacfileURLPtr
if pacfileURL == "" {
dwFlags = fWINHTTP_AUTOPROXY_AUTO_DETECT
dwAutoDetectFlags = fWINHTTP_AUTO_DETECT_TYPE_DNS_A | fWINHTTP_AUTO_DETECT_TYPE_DHCP
pfURLptr = nil
}
options := tWINHTTP_AUTOPROXY_OPTIONS{
dwFlags: dwFlags, // adding cache might cause issues: https://github.com/mattn/go-ieproxy/issues/6
dwAutoDetectFlags: dwAutoDetectFlags,
lpszAutoConfigUrl: pfURLptr,
lpvReserved: nil,
dwReserved: 0,
fAutoLogonIfChallenged: true, // may not be optimal https://msdn.microsoft.com/en-us/library/windows/desktop/aa383153(v=vs.85).aspx
} // lpszProxyBypass isn't used as this only executes in cases where there (may) be a pac file (autodetect can fail), where lpszProxyBypass couldn't be returned.
// in the case that autodetect fails and no pre-specified pacfile is present, no proxy is returned.
info := new(tWINHTTP_PROXY_INFO)
ret, _, err := winHttpGetProxyForURL.Call(
handle,
uintptr(unsafe.Pointer(URLPtr)),
uintptr(unsafe.Pointer(&options)),
uintptr(unsafe.Pointer(info)),
)
if ret > 0 {
err = nil
}
defer globalFreeWrapper(info.lpszProxyBypass)
defer globalFreeWrapper(info.lpszProxy)
return StringFromUTF16Ptr(info.lpszProxy), err
}