diff options
author | ale <ale@incal.net> | 2017-12-19 08:36:02 +0000 |
---|---|---|
committer | ale <ale@incal.net> | 2017-12-19 08:36:02 +0000 |
commit | 6f5bef5ffb58aab818cb46ad14310d2874cb1492 (patch) | |
tree | 9b0928f0b48496cd55b39d431a510379f07ba9f2 /client.go | |
parent | 979f2e8d216629f8beea4bb224686c73ddd0c4b6 (diff) | |
download | crawl-6f5bef5ffb58aab818cb46ad14310d2874cb1492.tar.gz crawl-6f5bef5ffb58aab818cb46ad14310d2874cb1492.zip |
Use a global http.Client with sane settings
Diffstat (limited to 'client.go')
-rw-r--r-- | client.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/client.go b/client.go new file mode 100644 index 0000000..c0c2626 --- /dev/null +++ b/client.go @@ -0,0 +1,31 @@ +package crawl + +import ( + "crypto/tls" + "net/http" + "net/http/cookiejar" + "time" +) + +var defaultClientTimeout = 60 * time.Second + +var DefaultClient *http.Client + +// DefaultClient returns a http.Client suitable for crawling: does not +// follow redirects, accepts invalid TLS certificates, sets a +// reasonable timeout for requests. +func init() { + jar, _ := cookiejar.New(nil) + DefaultClient = &http.Client{ + Timeout: defaultClientTimeout, + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + Jar: jar, + } +} |