#237·colly

RequestHandler bug

Author: llonchjCreated Oct 17, 2018Updated Jun 3, 2026
Labelsbug

I found a bug setting a Collector.RequestHandler func after a collector is initialized.

Setting Collector.RequestHandler, requires to execute c.backend.Client.CheckRedirect=c.checkRedirectFunc(). As c.backend is not accessible outside colly package, i will suggest to introduce a breaking change (might require version update according to golang/mod best practices) by renaming Collector.RedirectHandler to Collector.redirectHandler.

go
// SetRedirectHandler instructs the Collector to allow multiple downloads of the same URL
func (c *Collector) SetRedirectHandler(f func(req *http.Request, via []*http.Request) error) {
	c.redirectHandler = f
	c.backend.Client.CheckRedirect = c.checkRedirectFunc()
}

I can make a PR to address the issue. @asciimoo any thoughts?