Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
18 changes: 18 additions & 0 deletions http/pagerenderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package http

import (
"bytes"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions mirrorbits.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down