X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=fetch.go;h=d5cce10057e01d21a46ace24deac610c8c9e5d34;hb=4d994341317c2e700370950bd5fd9ac05963fc66;hp=491720a88786d0c363bc612048a6ce0e1f6b98b5;hpb=0ebeb1b4be72405243eadf39f297a13d6d391020;p=nsscash%2Fnsscash.git diff --git a/fetch.go b/fetch.go index 491720a..d5cce10 100644 --- a/fetch.go +++ b/fetch.go @@ -1,6 +1,6 @@ // Download files via HTTP with support for If-Modified-Since -// Copyright (C) 2019 Simon Ruderich +// Copyright (C) 2019-2020 Simon Ruderich // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by @@ -36,11 +36,14 @@ func init() { clients[""] = &http.Client{} } -func fetchIfModified(url, ca string, lastModified *time.Time) (int, []byte, error) { +func fetchIfModified(url, user, pass, ca string, lastModified *time.Time) (int, []byte, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { return 0, nil, err } + if user != "" || pass != "" { + req.SetBasicAuth(user, pass) + } if !lastModified.IsZero() { req.Header.Add("If-Modified-Since", lastModified.UTC().Format(http.TimeFormat))