mirror of https://github.com/perkeep/perkeep.git
s3 signing: use req.URL.Host if req.Host isn't set
This commit is contained in:
parent
f9d167d9cc
commit
17dc73b291
|
@ -23,11 +23,14 @@ import (
|
|||
"fmt"
|
||||
"http"
|
||||
"io"
|
||||
"log"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ = log.Printf
|
||||
|
||||
// See http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
|
||||
|
||||
type Auth struct {
|
||||
|
@ -40,7 +43,8 @@ func (a *Auth) SignRequest(req *http.Request) {
|
|||
req.Header.Set("Date", time.UTC().Format(http.TimeFormat))
|
||||
}
|
||||
hm := hmac.NewSHA1([]byte(a.SecretAccessKey))
|
||||
io.WriteString(hm, stringToSign(req))
|
||||
ss := stringToSign(req)
|
||||
io.WriteString(hm, ss)
|
||||
|
||||
authHeader := new(bytes.Buffer)
|
||||
fmt.Fprintf(authHeader, "AWS %s:", a.AccessKey)
|
||||
|
@ -148,6 +152,9 @@ const standardUSRegionAWS = "s3.amazonaws.com"
|
|||
|
||||
func bucketFromHostname(req *http.Request) string {
|
||||
host := req.Host
|
||||
if host == "" {
|
||||
host = req.URL.Host
|
||||
}
|
||||
if host == standardUSRegionAWS {
|
||||
return ""
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue