aboutsummaryrefslogtreecommitdiff
path: root/brokenlinks/worker.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-06-14 19:21:10 +0700
committerShulhan <ms@kilabit.info>2025-06-16 22:44:37 +0700
commitf9478c87f6e8553ce42c5fca91c2fc09f9f50d0f (patch)
treecd9e6945cf736853c623f00fdd6b9c48f42955e9 /brokenlinks/worker.go
parentfb9937797a07816fbc8b25fc03893f74bf7c7663 (diff)
downloadjarink-f9478c87f6e8553ce42c5fca91c2fc09f9f50d0f.tar.xz
brokenlinks: add option "insecure"
The insecure option will allow and not report as error on server with invalid certificates.
Diffstat (limited to 'brokenlinks/worker.go')
-rw-r--r--brokenlinks/worker.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/brokenlinks/worker.go b/brokenlinks/worker.go
index e3e0c45..8f278a8 100644
--- a/brokenlinks/worker.go
+++ b/brokenlinks/worker.go
@@ -4,6 +4,7 @@
package brokenlinks
import (
+ "crypto/tls"
"encoding/json"
"errors"
"fmt"
@@ -46,6 +47,8 @@ type worker struct {
log *log.Logger
+ httpc *http.Client
+
opts Options
// wg sync the goroutine scanner.
@@ -53,12 +56,31 @@ type worker struct {
}
func newWorker(opts Options) (wrk *worker, err error) {
+ var netDial = &net.Dialer{
+ Timeout: 30 * time.Second,
+ KeepAlive: 30 * time.Second,
+ }
+ var tlsConfig = &tls.Config{
+ InsecureSkipVerify: opts.Insecure,
+ }
+
wrk = &worker{
opts: opts,
seenLink: map[string]int{},
resultq: make(chan map[string]linkQueue, 100),
result: newResult(),
log: log.New(os.Stderr, ``, log.LstdFlags),
+ httpc: &http.Client{
+ Transport: &http.Transport{
+ DialContext: netDial.DialContext,
+ ExpectContinueTimeout: 1 * time.Second,
+ ForceAttemptHTTP2: true,
+ IdleConnTimeout: 90 * time.Second,
+ MaxIdleConns: 100,
+ TLSClientConfig: tlsConfig,
+ TLSHandshakeTimeout: 10 * time.Second,
+ },
+ },
}
wrk.scanUrl, err = url.Parse(opts.Url)
@@ -390,12 +412,12 @@ func (wrk *worker) fetch(linkq linkQueue) (
if wrk.opts.IsVerbose {
wrk.log.Printf("scan: HEAD %s\n", linkq.url)
}
- httpResp, err = http.Head(linkq.url)
+ httpResp, err = wrk.httpc.Head(linkq.url)
} else {
if wrk.opts.IsVerbose {
wrk.log.Printf("scan: GET %s\n", linkq.url)
}
- httpResp, err = http.Get(linkq.url)
+ httpResp, err = wrk.httpc.Get(linkq.url)
}
if err == nil {
return httpResp, nil