-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpac.go
34 lines (28 loc) · 1.01 KB
/
pac.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2022-2024 Sauce Labs Inc., all rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package forwarder
import (
"net/url"
"github.com/saucelabs/forwarder/log"
)
type PACResolver interface {
// FindProxyForURL calls FindProxyForURL or FindProxyForURLEx function in the PAC script.
// The hostname is optional, if empty it will be extracted from URL.
FindProxyForURL(url *url.URL, hostname string) (string, error)
}
type LoggingPACResolver struct {
Resolver PACResolver
Logger log.Logger
}
func (r *LoggingPACResolver) FindProxyForURL(u *url.URL, hostname string) (string, error) {
s, err := r.Resolver.FindProxyForURL(u, hostname)
if err != nil {
r.Logger.Errorf("FindProxyForURL(%q, %q) failed: %s", u.Redacted(), hostname, err)
} else {
r.Logger.Debugf("FindProxyForURL(%q, %q) -> %q", u.Redacted(), hostname, s)
}
return s, err
}