|
@@ -4,6 +4,7 @@ import (
|
|
"golang.org/x/net/proxy"
|
|
"golang.org/x/net/proxy"
|
|
"net"
|
|
"net"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
+ "net/url"
|
|
"os"
|
|
"os"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
@@ -16,6 +17,7 @@ type Controller interface {
|
|
ContextDialer() (proxy.Dialer, error)
|
|
ContextDialer() (proxy.Dialer, error)
|
|
ContextCookie() http.CookieJar
|
|
ContextCookie() http.CookieJar
|
|
ContextTimeout() time.Duration
|
|
ContextTimeout() time.Duration
|
|
|
|
+ ContextProxy() func(*http.Request) (*url.URL, error)
|
|
}
|
|
}
|
|
|
|
|
|
type Option func(*option)
|
|
type Option func(*option)
|
|
@@ -24,6 +26,7 @@ type option struct {
|
|
CookieJar http.CookieJar
|
|
CookieJar http.CookieJar
|
|
Timeout time.Duration
|
|
Timeout time.Duration
|
|
Dialer proxy.Dialer
|
|
Dialer proxy.Dialer
|
|
|
|
+ Proxy func(*http.Request) (*url.URL, error)
|
|
}
|
|
}
|
|
|
|
|
|
func WithCookie(cookieJar http.CookieJar) Option {
|
|
func WithCookie(cookieJar http.CookieJar) Option {
|
|
@@ -44,6 +47,12 @@ func WithDialer(dialer proxy.Dialer) Option {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func WithProxy(fn func(*http.Request) (*url.URL, error)) Option {
|
|
|
|
+ return func(opt *option) {
|
|
|
|
+ opt.Proxy = fn
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
type DefaultController struct {
|
|
type DefaultController struct {
|
|
*option
|
|
*option
|
|
Files map[string]*os.File
|
|
Files map[string]*os.File
|
|
@@ -110,6 +119,10 @@ func (c *DefaultController) ContextTimeout() time.Duration {
|
|
return c.Timeout
|
|
return c.Timeout
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (c *DefaultController) ContextProxy() func(*http.Request) (*url.URL, error) {
|
|
|
|
+ return c.Proxy
|
|
|
|
+}
|
|
|
|
+
|
|
type DialerWarp struct {
|
|
type DialerWarp struct {
|
|
dialer proxy.Dialer
|
|
dialer proxy.Dialer
|
|
}
|
|
}
|