diff --git a/config/config.go b/config/config.go index e264798d..cdc43622 100644 --- a/config/config.go +++ b/config/config.go @@ -86,6 +86,7 @@ type Configuration struct { CheckInterval int `yaml:"CheckInterval"` RepositoryScanInterval int `yaml:"RepositoryScanInterval"` MaxLinkHeaders int `yaml:"MaxLinkHeaders"` + CheckSumHeaders bool `yaml:"CheckSumHeaders"` FixTimezoneOffsets bool `yaml:"FixTimezoneOffsets"` Hashes hashing `yaml:"Hashes"` DisallowRedirects bool `yaml:"DisallowRedirects"` diff --git a/http/pagerenderer.go b/http/pagerenderer.go index 44f3f05f..e22d391f 100644 --- a/http/pagerenderer.go +++ b/http/pagerenderer.go @@ -5,6 +5,8 @@ package http import ( "bytes" + "encoding/base64" + "encoding/hex" "encoding/json" "errors" "fmt" @@ -91,6 +93,22 @@ func (w *RedirectRenderer) Write(ctx *Context, results *mirrors.Results) (status } } + // Generate checksum headers + if GetConfig().CheckSumHeaders { + if len(results.FileInfo.Md5) > 0 { + md5, _ := hex.DecodeString(results.FileInfo.Md5) + ctx.ResponseWriter().Header().Add("Content-MD5", fmt.Sprintf("%s", base64.StdEncoding.EncodeToString(md5))) + } + if len(results.FileInfo.Sha1) > 0 { + sha1, _ := hex.DecodeString(results.FileInfo.Sha1) + ctx.ResponseWriter().Header().Add("Content-SHA1", fmt.Sprintf("%s", base64.StdEncoding.EncodeToString(sha1))) + } + if len(results.FileInfo.Sha256) > 0 { + sha256, _ := hex.DecodeString(results.FileInfo.Sha256) + ctx.ResponseWriter().Header().Add("Content-SHA256", fmt.Sprintf("%s", base64.StdEncoding.EncodeToString(sha256))) + } + } + // Finally issue the redirect http.Redirect(ctx.ResponseWriter(), ctx.Request(), results.MirrorList[0].AbsoluteURL+path, http.StatusFound) return http.StatusFound, nil diff --git a/mirrorbits.conf b/mirrorbits.conf index 3373e691..af13be30 100644 --- a/mirrorbits.conf +++ b/mirrorbits.conf @@ -137,6 +137,10 @@ ## Affected mirrors will need to be rescanned after enabling this feature. # FixTimezoneOffsets: false +## Send Content-(MD5|SHA1|SHA256) headers +## requires the hashing algorithm to be enabled +# CheckSumHeaders: true + ## List of mirrors to use as fallback which will be used in case mirrorbits ## is unable to answer a request because the database is unreachable. ## Note: Mirrorbits will redirect to one of these mirrors based on the user