Skip to content

Commit

Permalink
Merge pull request gocolly#230 from bmancone/fix-229
Browse files Browse the repository at this point in the history
Fixes issue gocolly#229
  • Loading branch information
asciimoo authored Jan 14, 2019
2 parents 58e179a + 37b7efa commit a8a1b8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion _examples/instagram/instagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func main() {

c.OnRequest(func(r *colly.Request) {
r.Headers.Set("X-Requested-With", "XMLHttpRequest")
r.Headers.Set("Referrer", "https://www.instagram.com/"+instagramAccount)
r.Headers.Set("Referer", "https://www.instagram.com/"+instagramAccount)
if r.Ctx.Get("gis") != "" {
gis := fmt.Sprintf("%s:%s", r.Ctx.Get("gis"), r.Ctx.Get("variables"))
h := md5.New()
Expand Down
10 changes: 5 additions & 5 deletions extensions/referrer.go → extensions/referer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"github.com/gocolly/colly"
)

// Referrer sets valid Referrer HTTP header to requests.
// Referer sets valid Referer HTTP header to requests.
// Warning: this extension works only if you use Request.Visit
// from callbacks instead of Collector.Visit.
func Referrer(c *colly.Collector) {
func Referer(c *colly.Collector) {
c.OnResponse(func(r *colly.Response) {
r.Ctx.Put("_referrer", r.Request.URL.String())
r.Ctx.Put("_referer", r.Request.URL.String())
})
c.OnRequest(func(r *colly.Request) {
if ref := r.Ctx.Get("_referrer"); ref != "" {
r.Headers.Set("Referrer", ref)
if ref := r.Ctx.Get("_referer"); ref != "" {
r.Headers.Set("Referer", ref)
}
})
}

0 comments on commit a8a1b8b

Please sign in to comment.