private static Uri ComposeUrl(IRequest iRequest)
{
Uri url = iRequest.Endpoint;
var resourcePath = iRequest.ResourcePath;
if (resourcePath == null)
resourcePath = string.Empty;
else
{
if (resourcePath.StartsWith("/", StringComparison.Ordinal))
resourcePath = resourcePath.Substring(1);
}
// Construct any sub resource/query parameter additions to append to the
// resource path. Services like S3 which allow '?' and/or '&' in resource paths
// should use SubResources instead of appending them to the resource path with
// query string delimiters during request marshalling.
var delim = "?";
var sb = new StringBuilder();
if (iRequest.SubResources.Count > 0)
{
foreach (var subResource in iRequest.SubResources)
{
sb.AppendFormat("{0}{1}", delim, subResource.Key);
if (subResource.Value != null)
sb.AppendFormat("={0}", subResource.Value);
delim = "&";
}
}
if (iRequest.UseQueryString && iRequest.Parameters.Count > 0)
{
var queryString = SynthesizeSpeechPresignedUrlSigner.CanonicalizeQueryParametersForSynthesizeSpeech(iRequest.Parameters, true);
sb.AppendFormat("{0}{1}", delim, queryString);
}
if (AWSSDKUtils.HasBidiControlCharacters(resourcePath))
throw new AmazonClientException(string.Format(CultureInfo.InvariantCulture,
"Target resource path [{0}] has bidirectional characters, which are not supported" +
"by System.Uri and thus cannot be handled by the .NET SDK.", resourcePath));
var parameterizedPath = string.Concat(AWSSDKUtils.UrlEncode(resourcePath, true), sb);
var uri = new Uri(url.AbsoluteUri + parameterizedPath);
DontUnescapePathDotsAndSlashes(uri);
return uri;
}