Esempio n. 1
0
        /// <inheritdoc />
        public override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (!request.RequestUri.IsAbsoluteUri &&
                !request.RequestUri.OriginalString.StartsWith(this.RoutePrefix))
            {
                request.RequestUri = UriHelpers.RelativeEndpointUri(this.RoutePrefix, request.RequestUri.OriginalString);
            }

            return(base.SendAsync(request, cancellationToken));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RoutePrefixedHttpClientWrapper"/> class.
        /// </summary>
        /// <param name="client">
        /// HttpClient to wrap which has an absolute Uri Base Address set
        /// </param>
        /// <param name="routePrefix">
        /// The route prefix used when making requests to the remote endpoint
        /// </param>
        public RoutePrefixedHttpClientWrapper(HttpClient client, string routePrefix)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (client.BaseAddress == null)
            {
                throw new ArgumentException("Base Address cannot be null.");
            }

            if (!client.BaseAddress.IsAbsoluteUri)
            {
                throw new ArgumentException("Base Address must be an absolute Uri.");
            }

            this.Client      = client;
            this.RoutePrefix = UriHelpers.EnsureNoLeadingSlash(UriHelpers.EnsureNoTrailingSlash(routePrefix));
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RoutePrefixedHttpClient"/> class
 /// </summary>
 /// <param name="routePrefix">
 /// Route Prefix used when making requests to the remote server
 /// </param>
 /// <param name="handler">
 /// The HTTP handler stack to use for sending requests.
 /// </param>
 /// <param name="disposeHandler">
 /// true if the inner handler should be disposed of by Dispose(), false if you intend
 /// to reuse the inner handler.
 /// </param>
 public RoutePrefixedHttpClient(HttpMessageHandler handler, bool disposeHandler, string routePrefix)
     : base(handler, disposeHandler)
 {
     this.RoutePrefix = UriHelpers.EnsureNoLeadingSlash(UriHelpers.EnsureNoTrailingSlash(routePrefix));
 }
Esempio n. 4
0
        public static Task <HttpResponseMessage> PutAsync(this HttpClient client, string routePrefix, string relativeRequestUri, HttpContent content = null, IEnumerable <KeyValuePair <string, IEnumerable <string> > > additionalHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Uri relativeUri = UriHelpers.RelativeEndpointUri(routePrefix, relativeRequestUri);

            return(client.PutAsync(relativeUri, content, additionalHeaders, cancellationToken));
        }
Esempio n. 5
0
        public static Task <string> GetStringAsync(this HttpClient client, string routePrefix, string relativeRequestUri)
        {
            Uri relativeUri = UriHelpers.RelativeEndpointUri(routePrefix, relativeRequestUri);

            return(client.GetStringAsync(relativeUri));
        }