aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorale <ale@incal.net>2017-12-19 08:36:02 +0000
committerale <ale@incal.net>2017-12-19 08:36:02 +0000
commit6f5bef5ffb58aab818cb46ad14310d2874cb1492 (patch)
tree9b0928f0b48496cd55b39d431a510379f07ba9f2 /client.go
parent979f2e8d216629f8beea4bb224686c73ddd0c4b6 (diff)
downloadcrawl-6f5bef5ffb58aab818cb46ad14310d2874cb1492.tar.gz
crawl-6f5bef5ffb58aab818cb46ad14310d2874cb1492.zip
Use a global http.Client with sane settings
Diffstat (limited to 'client.go')
-rw-r--r--client.go31
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,
+ }
+}