Skip to content

Commit

Permalink
Merge pull request #59 from mnhkahn/fix_proxy_nil
Browse files Browse the repository at this point in the history
fix(proxy): Fix nil pointer error if got 301 status code
  • Loading branch information
mnhkahn authored Feb 19, 2019
2 parents 9ba312e + c7d8d6e commit fd5601c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/mnhkahn/maodou
require (
github.com/PuerkitoBio/goquery v1.4.1
github.com/andybalholm/cascadia v1.0.0 // indirect
github.com/mnhkahn/gogogo v1.0.2
github.com/mnhkahn/gogogo v1.0.3
github.com/mnhkahn/peanut v1.0.3
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ github.com/mnhkahn/gogogo v1.0.1 h1:nQqxYUvAf1uxTbrExD7+3KuBMpFa4nTaDk2h9GB0Wp8=
github.com/mnhkahn/gogogo v1.0.1/go.mod h1:2H7pELixbPqzXoX5mOT8co8aTkhZpl5gVb4CcZDJO54=
github.com/mnhkahn/gogogo v1.0.2 h1:uFhGfOz5y4hsRztE7HA3yQW58lQ6ATDl53ezC5NHq1M=
github.com/mnhkahn/gogogo v1.0.2/go.mod h1:KM3JDQ9Xx9atIfBnKhEErETA/J1uMsFFK1ld4nwuBig=
github.com/mnhkahn/gogogo v1.0.3 h1:jI+Puc/5gd8ZTizU8ap4LnJKp6HK66f4NR9EO0+gcX8=
github.com/mnhkahn/gogogo v1.0.3/go.mod h1:KM3JDQ9Xx9atIfBnKhEErETA/J1uMsFFK1ld4nwuBig=
github.com/mnhkahn/peanut v0.0.0-20180828055434-ec108b6c00a8 h1:c+s8E7JbEkhN/mTkSS7cGqAr0TiJXUpEWz5M1r0OmtY=
github.com/mnhkahn/peanut v0.0.0-20180830083834-4b0ce468b4f3 h1:MsxWo97ApFYCFczGfthp/9vGTKxOW+OUYrzeuti8Ieg=
github.com/mnhkahn/peanut v0.0.0-20180830083834-4b0ce468b4f3/go.mod h1:z/P9SGuhOq6nOGkrGXYZR7UDUPHUSpAFTSmfA+tVKoA=
Expand Down
7 changes: 4 additions & 3 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ func (this *Request) Cawl(paras ...interface{}) (*Response, error) {
logger.Debug("Cawl Success.")
}
} else {
if len(paras) == 1 || (len(paras) == 2 && paras[1].(int) == CawlProxy) {
this.proxy.DeleteProxy(p.Id)
}
if len(paras) == 2 && paras[1].(int) == CawlRetry {
logger.Debug("Retry...")
this.Cawl(paras...)
Expand All @@ -114,6 +111,10 @@ func (this *Request) Cawl(paras ...interface{}) (*Response, error) {
}
return this.Cawl(http_resp.Header.Get("Location"))
} else {
if len(paras) == 1 || (len(paras) == 2 && paras[1].(int) == CawlProxy) {
this.proxy.DeleteProxy(p.Id)
}

logger.Info("Cawl Got Status Code %d.\n", http_resp.StatusCode)
return resp, fmt.Errorf("Cawl Got Status Code %d.", http_resp.StatusCode)
}
Expand Down

0 comments on commit fd5601c

Please sign in to comment.