@@ -10,6 +10,7 @@ import (
10
10
"math/rand"
11
11
"net"
12
12
"net/http"
13
+ "net/url"
13
14
"strings"
14
15
"sync/atomic"
15
16
"time"
@@ -125,7 +126,7 @@ func isContentType(contentType string, h *http.Header) bool {
125
126
// see:
126
127
// https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
127
128
// https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
128
- func getUrlContent (url , contentType string , bootstrap []string , timeout time.Duration ) (string , error ) {
129
+ func getUrlContent (theUrl , contentType string , bootstrap []string , timeout time.Duration ) (string , error ) {
129
130
var transport http.RoundTripper
130
131
131
132
if len (bootstrap ) != 0 {
@@ -156,7 +157,7 @@ func getUrlContent(url, contentType string, bootstrap []string, timeout time.Dur
156
157
// Fallback to use system default resolvers, which located at /etc/resolv.conf
157
158
}
158
159
159
- req , err := http .NewRequest (http .MethodGet , url , nil )
160
+ req , err := http .NewRequest (http .MethodGet , theUrl , nil )
160
161
if err != nil {
161
162
return "" , err
162
163
}
@@ -178,10 +179,10 @@ func getUrlContent(url, contentType string, bootstrap []string, timeout time.Dur
178
179
}
179
180
180
181
if len (contentType ) != 0 && ! isContentType (contentType , & resp .Header ) {
181
- if url , err : = fixUrl (url , resp .Header ); err != nil {
182
+ if theUrl , err = fixUrl (theUrl , resp .Header ); err != nil {
182
183
return "" , err
183
184
} else {
184
- return getUrlContent (url , contentType , bootstrap , timeout )
185
+ return getUrlContent (theUrl , contentType , bootstrap , timeout )
185
186
}
186
187
}
187
188
@@ -193,13 +194,16 @@ func getUrlContent(url, contentType string, bootstrap []string, timeout time.Dur
193
194
return string (content ), nil
194
195
}
195
196
196
- func fixUrl (url string , h http.Header ) (string , error ) {
197
+ func fixUrl (theUrl string , h http.Header ) (string , error ) {
197
198
const LocationKey = "Location"
198
199
location := h .Get (LocationKey )
199
200
if location != "" {
201
+ if _ , err := url .Parse (theUrl ); err != nil {
202
+ return "" , fmt .Errorf ("fixUrl(): url.Parse(): %w" , err )
203
+ }
200
204
return location , nil
201
205
}
202
- return "" , fmt .Errorf ("%q header key not found in %v" , LocationKey , url )
206
+ return "" , fmt .Errorf ("%q header key not found in %v" , LocationKey , theUrl )
203
207
}
204
208
205
209
func stringHash (str string ) uint64 {
0 commit comments