Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
fix #11: prevent redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Apr 25, 2018
1 parent eb46ed0 commit b53c0a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion http/availability/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *Report) Get() error {
if r.error != nil {
return r.error
}
c := colly.NewCollector(colly.UserAgent("check"), colly.IgnoreRobotsTxt())
c := colly.NewCollector(UserAgent(), IgnoreRedirect())
c.OnRequest(func(req *colly.Request) {
link := r.createLink(req.URL)
if link.IsPage {
Expand Down
19 changes: 19 additions & 0 deletions http/availability/scrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package availability

import (
"net/http"

"github.com/gocolly/colly"
)

func UserAgent() func(*colly.Collector) {
return colly.UserAgent("check")
}

func IgnoreRedirect() func(*colly.Collector) {
return func(c *colly.Collector) {
c.RedirectHandler = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
}
}

0 comments on commit b53c0a8

Please sign in to comment.