]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - fetch.go
.github: update upstream actions to latest version
[nsscash/nsscash.git] / fetch.go
index ba1bbc8f4bde2019503102a1100ea1cf01bcc0a0..2c785a264f51685533a78e0f02544bc8794beed9 100644 (file)
--- 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-2021  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,14 +36,17 @@ 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.Format(http.TimeFormat))
+                       lastModified.UTC().Format(http.TimeFormat))
        }
 
        client, ok := clients[ca]