@@ -238,6 +238,22 @@ public static string GenerateSignature(string applicationSecret, string consumer
238238 return $ "$1${ signature } ";
239239 }
240240
241+ private string GetTarget ( string path )
242+ {
243+ if ( path . StartsWith ( "/" ) )
244+ {
245+ path = path . Substring ( 1 ) ;
246+ }
247+
248+ var endpoint = Endpoint . ToString ( ) ;
249+ if ( endpoint . EndsWith ( "/1.0/" ) && ( path . StartsWith ( "v1/" ) || path . StartsWith ( "v2/" ) ) )
250+ {
251+ endpoint = endpoint . Substring ( 0 , endpoint . Length - 4 ) ;
252+ }
253+
254+ return new Uri ( endpoint ) + path ;
255+ }
256+
241257 private async Task SetHeaders ( HttpRequestMessage msg , string method , string target , string data , bool needAuth , bool isBatch = false )
242258 {
243259 var headers = msg . Headers ;
@@ -317,23 +333,19 @@ public async Task<long> GetTimeDelta()
317333 /// <exception cref="InvalidResponseException">when API response could not be decoded</exception>
318334 private async Task < string > CallAsync ( string method , string path , string data = null , bool needAuth = true , bool isBatch = false , TimeSpan ? timeout = null )
319335 {
320- if ( path . StartsWith ( "/" ) )
321- {
322- path = path . Substring ( 1 ) ;
323- }
324-
325336 HttpResponseMessage response = null ;
326337
327338 try
328339 {
329340 var httpMethod = new HttpMethod ( method ) ;
330- HttpRequestMessage msg = new HttpRequestMessage ( httpMethod , new Uri ( Endpoint + path ) ) ;
341+ var target = GetTarget ( path ) ;
342+ HttpRequestMessage msg = new HttpRequestMessage ( httpMethod , target ) ;
331343 if ( httpMethod != HttpMethod . Get && data != null )
332344 {
333345 msg . Content = new StringContent ( data ?? "" , Encoding . UTF8 , "application/json" ) ;
334346 }
335347
336- await SetHeaders ( msg , method , Endpoint + path , data , needAuth , isBatch ) . ConfigureAwait ( false ) ;
348+ await SetHeaders ( msg , method , target . ToString ( ) , data , needAuth , isBatch ) . ConfigureAwait ( false ) ;
337349
338350 using ( var cts = new CancellationTokenSource ( timeout ?? _defaultTimeout ) )
339351 {
0 commit comments