Skip to content

Commit

Permalink
[enh] add Abort function to Request
Browse files Browse the repository at this point in the history
  • Loading branch information
asciimoo committed Jan 19, 2018
1 parent dface0b commit 44e1340
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions colly.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ func (c *Collector) scrape(u, method string, depth int, requestData io.Reader, c

c.handleOnRequest(request)

if request.abort {
return nil
}

if method == "POST" && req.Header.Get("Content-Type") == "" {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
}
Expand Down
6 changes: 6 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ type Request struct {
// ID is the Unique identifier of the request
ID uint32
collector *Collector
abort bool
}

// Abort cancels the HTTP request when called in an OnRequest callback
func (r *Request) Abort() {
r.abort = true
}

// AbsoluteURL returns with the resolved absolute URL of an URL chunk.
Expand Down

0 comments on commit 44e1340

Please sign in to comment.