From c7d8d6ed1c43173c83a07c4f74c42423c097f9a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=B6=85?= Date: Tue, 19 Feb 2019 14:07:47 +0800 Subject: [PATCH] fix(proxy): Fix nil pointer error if got 301 status code --- go.mod | 2 +- go.sum | 2 ++ request.go | 7 ++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 8942ba1..cfdddfb 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index b13a6be..d083bb3 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/request.go b/request.go index 3af28a2..75da676 100644 --- a/request.go +++ b/request.go @@ -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...) @@ -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) }