@@ -10,6 +10,7 @@ import (
1010 "crypto/rsa"
1111 "io/ioutil"
1212 "net/http"
13+ "time"
1314)
1415
1516var defaultHeaders = []string {"content-type" , "content-length" , "host" } // also request path and digest
@@ -32,7 +33,10 @@ func sliceHas(haystack []string, needle string) bool {
3233// included on each request. Multiple included signatures allow you to gracefully introduce stronger
3334// algorithms, rotate keys, etc.
3435func NewSignTransport (transport http.RoundTripper , opts ... signOption ) http.RoundTripper {
35- s := signer {}
36+ s := signer {
37+ keys : map [string ]sigHolder {},
38+ nowFunc : time .Now ,
39+ }
3640
3741 for _ , o := range opts {
3842 o .configureSign (& s )
@@ -45,8 +49,8 @@ func NewSignTransport(transport http.RoundTripper, opts ...signOption) http.Roun
4549 // TODO: normalize headers? lowercase & de-dupe
4650
4751 // request path first, for aesthetics
48- if ! sliceHas (s .headers , "@request-path " ) {
49- s .headers = append ([]string {"@request-path " }, s .headers ... )
52+ if ! sliceHas (s .headers , "@request-target " ) {
53+ s .headers = append ([]string {"@request-target " }, s .headers ... )
5054 }
5155
5256 if ! sliceHas (s .headers , "digest" ) {
@@ -84,7 +88,7 @@ func NewSignTransport(transport http.RoundTripper, opts ...signOption) http.Roun
8488 nr .Header [k ] = v
8589 }
8690
87- return transport .RoundTrip (r )
91+ return transport .RoundTrip (nr )
8892 })
8993}
9094
@@ -104,7 +108,10 @@ func (r rt) RoundTrip(req *http.Request) (*http.Response, error) { return r(req)
104108func NewVerifyMiddleware (opts ... verifyOption ) func (http.Handler ) http.Handler {
105109
106110 // TODO: form and multipart support
107- v := verifier {}
111+ v := verifier {
112+ keys : make (map [string ]verHolder ),
113+ nowFunc : time .Now ,
114+ }
108115
109116 for _ , o := range opts {
110117 o .configureVerify (& v )
0 commit comments