summaryrefslogtreecommitdiff
path: root/modules/proxy
diff options
context:
space:
mode:
Diffstat (limited to 'modules/proxy')
-rw-r--r--modules/proxy/proxy.go4
-rw-r--r--modules/proxy/proxy_test.go11
2 files changed, 10 insertions, 5 deletions
diff --git a/modules/proxy/proxy.go b/modules/proxy/proxy.go
index 120a856..ff9aa5c 100644
--- a/modules/proxy/proxy.go
+++ b/modules/proxy/proxy.go
@@ -19,6 +19,7 @@ func init() {
type Module struct {
Proxies []string `json:"proxies"`
+ Proxy string `json:"proxy"`
transports []*http.Transport
}
@@ -35,13 +36,14 @@ func (m *Module) Provision(ctx flyscrape.Context) {
return
}
- for _, purl := range m.Proxies {
+ for _, purl := range append(m.Proxies, m.Proxy) {
if parsed, err := url.Parse(purl); err == nil {
m.transports = append(m.transports, &http.Transport{
Proxy: http.ProxyURL(parsed),
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
})
}
+
}
}
diff --git a/modules/proxy/proxy_test.go b/modules/proxy/proxy_test.go
index 62da23a..219649e 100644
--- a/modules/proxy/proxy_test.go
+++ b/modules/proxy/proxy_test.go
@@ -35,19 +35,21 @@ func TestProxy(t *testing.T) {
}
func TestProxyMultiple(t *testing.T) {
- calls := []int{0, 0}
+ calls := []int{0, 0, 0}
p0 := newProxy(func() { calls[0]++ })
p1 := newProxy(func() { calls[1]++ })
+ p2 := newProxy(func() { calls[2]++ })
defer p0.Close()
defer p1.Close()
+ defer p2.Close()
- mod := &proxy.Module{Proxies: []string{p0.URL, p1.URL}}
+ mod := &proxy.Module{Proxies: []string{p0.URL, p1.URL}, Proxy: p2.URL}
mod.Provision(nil)
trans := mod.AdaptTransport(nil)
req := httptest.NewRequest("GET", "http://www.example.com/", nil)
- for i := 0; i < 10; i++ {
+ for i := 0; i < 50; i++ {
resp, err := trans.RoundTrip(req)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
@@ -55,7 +57,8 @@ func TestProxyMultiple(t *testing.T) {
require.Greater(t, calls[0], 1)
require.Greater(t, calls[1], 1)
- require.Equal(t, 10, calls[0]+calls[1])
+ require.Greater(t, calls[2], 1)
+ require.Equal(t, 50, calls[0]+calls[1]+calls[2])
}
func newProxy(f func()) *httptest.Server {