예제 #1
0
        public static async Task <Uri> AddKeyToQueryStringAsync(
            this IApiKeyProvider apiKeyProvider,
            Uri url,
            CancellationToken cancellationToken)
        {
            // Validate parameters.
            if (apiKeyProvider == null)
            {
                throw new ArgumentNullException(nameof(apiKeyProvider));
            }
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }

            // Call the overload.
            return(new Uri(await apiKeyProvider.AddKeyToQueryStringAsync(url.ToString(), cancellationToken).ConfigureAwait(false)));
        }
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken
            )
        {
            // Validate parameters.
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            // Add the key to the URL.
            request.RequestUri = await _apiKeyProvider
                                 .AddKeyToQueryStringAsync(request.RequestUri, cancellationToken)
                                 .ConfigureAwait(false);

            // Call the base.
            // TODO: Should the original request URI be restored?
            return(await base
                   .SendAsync(request, cancellationToken)
                   .ConfigureAwait(false));
        }