@@ -16,10 +16,10 @@ class AWS4RequestSigner
1616 {
1717 private readonly string _access_key ;
1818 private readonly string _secret_key ;
19- private readonly string _token ;
19+ private readonly string ? _token ;
2020 private const string algorithm = "AWS4-HMAC-SHA256" ;
2121
22- public AWS4RequestSigner ( string accessKey , string secretKey , string token = null )
22+ public AWS4RequestSigner ( string accessKey , string secretKey , string ? token = null )
2323 {
2424
2525 if ( string . IsNullOrEmpty ( accessKey ) )
@@ -108,9 +108,11 @@ public async Task<HttpRequestMessage> Sign(HttpRequestMessage request, string se
108108 throw new ArgumentNullException ( nameof ( request ) ) ;
109109 }
110110
111+ var uri = request . RequestUri ?? throw new ArgumentException ( "requst.RequestUri can't be null" , nameof ( request ) ) ;
112+
111113 if ( request . Headers . Host == null )
112114 {
113- request . Headers . Host = request . RequestUri . Host ;
115+ request . Headers . Host = uri . Host ;
114116 }
115117
116118 var t = DateTimeOffset . UtcNow ;
@@ -120,7 +122,7 @@ public async Task<HttpRequestMessage> Sign(HttpRequestMessage request, string se
120122
121123 var canonical_request = new StringBuilder ( ) ;
122124 canonical_request . Append ( request . Method + "\n " ) ;
123- var canonical_uri = GetPath ( request . RequestUri ) ;
125+ var canonical_uri = GetPath ( uri ) ;
124126 canonical_request . Append ( canonical_uri ) ;
125127 canonical_request . Append ( "\n " ) ;
126128
@@ -172,7 +174,8 @@ public async Task<HttpRequestMessage> Sign(HttpRequestMessage request, string se
172174
173175 private static string GetCanonicalQueryParams ( HttpRequestMessage request )
174176 {
175- var querystring = HttpUtility . ParseQueryString ( request . RequestUri . Query ) ;
177+ var uri = request . RequestUri ?? throw new ArgumentException ( nameof ( request ) ) ;
178+ var querystring = HttpUtility . ParseQueryString ( uri . Query ) ;
176179 var keys = querystring . AllKeys . OrderBy ( a => a ) . ToArray ( ) ;
177180 var queryParams = keys . Select ( key => $ "{ key } ={ querystring [ key ] } ") ;
178181 var canonicalQueryParams = string . Join ( "&" , queryParams ) ;
0 commit comments