MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / WrapJSFindProxyForURLFunc

Function WrapJSFindProxyForURLFunc

dialer/jsrouter.go:24–56  ·  view source on GitHub ↗
(f JSFindProxyForURLFunc, logger *clog.CondLogger)

Source from the content-addressed store, hash-verified

22type JSFindProxyForURLFunc = func(url, host string) (string, error)
23
24func WrapJSFindProxyForURLFunc(f JSFindProxyForURLFunc, logger *clog.CondLogger) JSRouterFunc {
25 return func(req *jsext.JSRequestInfo, dst *jsext.JSDstInfo, _ string) (string, error) {
26 h := dst.OriginalHost
27 scheme := "https"
28 if req != nil && req.Method != "CONNECT" {
29 scheme = "http"
30 }
31 u := &url.URL{
32 Scheme: scheme,
33 Host: net.JoinHostPort(dst.OriginalHost, strconv.Itoa(int(dst.Port))),
34 }
35 pSpec, err := f(u.String(), h)
36 if err != nil {
37 return "", err
38 }
39 logger.Debug("FindProxyForURL(%q, %q) -> %q", u, h, pSpec)
40 pSpec, _, _ = strings.Cut(pSpec, ";")
41 pSpec = strings.TrimSpace(pSpec)
42 pType, pAddr, _ := strings.Cut(pSpec, " ")
43 pAddr = strings.TrimSpace(pAddr)
44 switch pType {
45 case "", "DIRECT":
46 return "", nil
47 case "HTTP", "PROXY":
48 return "http://" + pAddr, nil
49 case "HTTPS":
50 return "https://" + pAddr, nil
51 case "SOCKS", "SOCKS5":
52 return "socks5://" + pAddr, nil
53 }
54 return "", fmt.Errorf("FindProxyForURL returned unsupported proxy type: %q", pType)
55 }
56}
57
58type JSRouter struct {
59 funcPool chan JSRouterFunc

Callers 1

NewJSRouterFunction · 0.85

Calls 3

ErrorfMethod · 0.80
StringMethod · 0.45
DebugMethod · 0.45

Tested by

no test coverage detected