@@ -21,13 +21,20 @@ type Signer interface {
21
21
22
22
type DefaultSigner struct {
23
23
config * Config
24
+
25
+ // noEscape represents the characters that AWS doesn't escape
26
+ noEscape [256 ]bool
24
27
}
25
28
26
29
func NewDefaultSigner (config * Config ) Signer {
27
- // initialize noEscape array. This way we can avoid using init() functions
28
- for i := 0 ; i < len (noEscape ); i ++ {
30
+ ds := & DefaultSigner {
31
+ config : config ,
32
+ noEscape : [256 ]bool {},
33
+ }
34
+
35
+ for i := 0 ; i < len (ds .noEscape ); i ++ {
29
36
// AWS expects every character except these to be escaped
30
- noEscape [i ] = (i >= 'A' && i <= 'Z' ) ||
37
+ ds . noEscape [i ] = (i >= 'A' && i <= 'Z' ) ||
31
38
(i >= 'a' && i <= 'z' ) ||
32
39
(i >= '0' && i <= '9' ) ||
33
40
i == '-' ||
@@ -36,7 +43,7 @@ func NewDefaultSigner(config *Config) Signer {
36
43
i == '~'
37
44
}
38
45
39
- return & DefaultSigner { config : config }
46
+ return ds
40
47
}
41
48
42
49
func (d * DefaultSigner ) Sign (req * http.Request ) error {
@@ -59,7 +66,7 @@ func (d *DefaultSigner) Sign(req *http.Request) error {
59
66
canonicalQueryString := getCanonicalQueryString (req .URL )
60
67
canonicalReq := buildCanonicalString (
61
68
req .Method ,
62
- getCanonicalURI (req .URL ),
69
+ getCanonicalURI (req .URL , d . noEscape ),
63
70
canonicalQueryString ,
64
71
canonicalHeaderStr ,
65
72
signedHeadersStr ,
@@ -136,6 +143,7 @@ var ignoredHeaders = map[string]struct{}{
136
143
"Expect" : struct {}{},
137
144
}
138
145
146
+ // buildCanonicalHeaders is mostly ported from https://github.com/aws/aws-sdk-go-v2/aws/signer/v4 buildCanonicalHeaders
139
147
func buildCanonicalHeaders (req * http.Request ) (signed http.Header , signedHeaders , canonicalHeadersStr string ) {
140
148
host , header , length := req .Host , req .Header , req .ContentLength
141
149
@@ -203,8 +211,8 @@ func buildCanonicalHeaders(req *http.Request) (signed http.Header, signedHeaders
203
211
return signed , signedHeaders , canonicalHeadersStr
204
212
}
205
213
206
- func getCanonicalURI (u * url.URL ) string {
207
- return escapePath (getURIPath (u ), false )
214
+ func getCanonicalURI (u * url.URL , noEscape [ 256 ] bool ) string {
215
+ return escapePath (getURIPath (u ), false , noEscape )
208
216
}
209
217
210
218
func getCanonicalQueryString (u * url.URL ) string {
0 commit comments