(rec int, u string, progress string, foundUrls *[]string, stat string)
| 219 | } |
| 220 | |
| 221 | func runTests(rec int, u string, progress string, foundUrls *[]string, stat string) { |
| 222 | var repWebsite pkg.ReportWebsite |
| 223 | var err error |
| 224 | |
| 225 | msg := fmt.Sprintf("\nTesting website%s: %s\n", progress, u) |
| 226 | pkg.Print(msg, pkg.NoColor) |
| 227 | pkg.Print("===============================================================\n", pkg.NoColor) |
| 228 | |
| 229 | if !strings.HasPrefix(u, "http://") && !strings.HasPrefix(u, "https://") { |
| 230 | if pkg.Config.UseHTTP { |
| 231 | u = "http://" + u |
| 232 | } else { |
| 233 | u = "https://" + u |
| 234 | } |
| 235 | } |
| 236 | repWebsite.URL = u |
| 237 | |
| 238 | /* Setting up client: cookies and noredirect */ |
| 239 | msg = "Setting up client\n" |
| 240 | pkg.PrintVerbose(msg, pkg.NoColor, 2) |
| 241 | |
| 242 | // Setting cookies, specified by setcookies |
| 243 | pkg.Config.Website.Cookies = map[string]string{} |
| 244 | for _, c := range pkg.Config.Cookies { |
| 245 | c = strings.TrimSuffix(c, "\r") |
| 246 | c = strings.TrimSpace(c) |
| 247 | if c == "" { |
| 248 | continue |
| 249 | } else if !strings.Contains(c, "=") { |
| 250 | msg = "Specified cookie %s doesn't contain a = and will be skipped\n" |
| 251 | pkg.PrintVerbose(msg, pkg.NoColor, 2) |
| 252 | continue |
| 253 | } else { |
| 254 | cSlice := strings.SplitAfterN(c, "=", 2) |
| 255 | cSlice[0] = strings.TrimSuffix(cSlice[0], "=") |
| 256 | |
| 257 | pkg.Config.Website.Cookies[cSlice[0]] = cSlice[1] |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | timeOutDuration := time.Duration(time.Duration(pkg.Config.TimeOut) * time.Second) |
| 262 | clientNoRedir := &http.Client{ |
| 263 | CheckRedirect: func(redirRequest *http.Request, via []*http.Request) error { |
| 264 | /* Commented out, because it unnecessary bloats up logs, especially for 301/302 links |
| 265 | msg := fmt.Sprintf("Redirect Request denied: %s\n", redirRequest.Header) |
| 266 | pkg.PrintVerbose(msg, pkg.Yellow, 2) |
| 267 | */ |
| 268 | return http.ErrUseLastResponse |
| 269 | }, |
| 270 | Timeout: timeOutDuration, |
| 271 | } |
| 272 | |
| 273 | http.DefaultClient = clientNoRedir |
| 274 | |
| 275 | // retrieve cookies, headers etc. Only setStatusCode if no cookies shall be accepted. Otherwise the next request with set Cookies sets the status code |
| 276 | if !pkg.Config.DeclineCookies { |
| 277 | pkg.Config.Website, err = pkg.GetWebsite(u, false, false) |
| 278 | } else { |
no test coverage detected