From 41aac2959b498a62fed271a18ea763be1b49ccc8 Mon Sep 17 00:00:00 2001 From: jhezjkp Date: Sat, 13 Aug 2016 16:50:58 +0800 Subject: [PATCH] fix file download problem with a urls which includes a port #9 --- http.go | 7 ++++++- http_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/http.go b/http.go index 642b027..0136d83 100644 --- a/http.go +++ b/http.go @@ -43,9 +43,14 @@ func NewHttpDownloader(url string, par int, skipTls bool) *HttpDownloader { var resumable = true parsed, err := stdurl.Parse(url) + var host = parsed.Host + var portIndex = strings.Index(host, ":") + if portIndex >= 0 { + host = host[0:portIndex] + } FatalCheck(err) - ips, err := net.LookupIP(parsed.Host) + ips, err := net.LookupIP(host) FatalCheck(err) ipstr := FilterIPV4(ips) diff --git a/http_test.go b/http_test.go index 44181eb..f8a2cac 100644 --- a/http_test.go +++ b/http_test.go @@ -25,3 +25,10 @@ func TestPartCalculate(t *testing.T) { t.Fatalf("part range was wrong") } } + +func TestNewHttpDownloader(t *testing.T) { + displayProgress = false + + NewHttpDownloader("http://www.golangtc.com:80/static/go/1.7rc6/go1.7rc6.darwin-amd64.pkg", 1, true) + NewHttpDownloader("http://www.golangtc.com/static/go/1.7rc6/go1.7rc6.darwin-amd64.pkg", 1, true) +}