@@ -21,13 +21,20 @@ type Signer interface {
2121
2222type  DefaultSigner  struct  {
2323	config  * Config 
24+ 
25+ 	// noEscape represents the characters that AWS doesn't escape 
26+ 	noEscape  [256 ]bool 
2427}
2528
2629func  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 ++  {
2936		// AWS expects every character except these to be escaped 
30- 		noEscape [i ] =  (i  >=  'A'  &&  i  <=  'Z' ) || 
37+ 		ds . noEscape [i ] =  (i  >=  'A'  &&  i  <=  'Z' ) || 
3138			(i  >=  'a'  &&  i  <=  'z' ) || 
3239			(i  >=  '0'  &&  i  <=  '9' ) || 
3340			i  ==  '-'  || 
@@ -36,7 +43,7 @@ func NewDefaultSigner(config *Config) Signer {
3643			i  ==  '~' 
3744	}
3845
39- 	return  & DefaultSigner { config :  config } 
46+ 	return  ds 
4047}
4148
4249func  (d  * DefaultSigner ) Sign (req  * http.Request ) error  {
@@ -59,7 +66,7 @@ func (d *DefaultSigner) Sign(req *http.Request) error {
5966	canonicalQueryString  :=  getCanonicalQueryString (req .URL )
6067	canonicalReq  :=  buildCanonicalString (
6168		req .Method ,
62- 		getCanonicalURI (req .URL ),
69+ 		getCanonicalURI (req .URL ,  d . noEscape ),
6370		canonicalQueryString ,
6471		canonicalHeaderStr ,
6572		signedHeadersStr ,
@@ -136,6 +143,7 @@ var ignoredHeaders = map[string]struct{}{
136143	"Expect" :          struct {}{},
137144}
138145
146+ // buildCanonicalHeaders is mostly ported from https://github.com/aws/aws-sdk-go-v2/aws/signer/v4 buildCanonicalHeaders 
139147func  buildCanonicalHeaders (req  * http.Request ) (signed  http.Header , signedHeaders , canonicalHeadersStr  string ) {
140148	host , header , length  :=  req .Host , req .Header , req .ContentLength 
141149
@@ -203,8 +211,8 @@ func buildCanonicalHeaders(req *http.Request) (signed http.Header, signedHeaders
203211	return  signed , signedHeaders , canonicalHeadersStr 
204212}
205213
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 )
208216}
209217
210218func  getCanonicalQueryString (u  * url.URL ) string  {
0 commit comments