Exemple #1
0
        /// <summary>
        /// Attaches an HTTP request configuration instance to the given message as custom property.
        /// If the configuration has already been set on the request message, the old configuration
        /// is replaced.
        /// </summary>
        /// <param name="request">The HTTP request message.</param>
        /// <param name="configuration">An HTTP request message configuration instance.</param>
        public static void SetConfiguration(this HttpRequestMessage request, HttpRequestMessageConfiguration configuration)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            request.Properties[NuGetConfigurationKey] = configuration;
        }
        /// <summary>
        /// Attaches an HTTP request configuration instance to the given message as custom property.
        /// If the configuration has already been set on the request message, the old configuration
        /// is replaced.
        /// </summary>
        /// <param name="request">The HTTP request message.</param>
        /// <param name="configuration">An HTTP request message configuration instance.</param>
        public static void SetConfiguration(this HttpRequestMessage request, HttpRequestMessageConfiguration configuration)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

#if NET5_0_OR_GREATER
            request.Options.Set(new HttpRequestOptionsKey <HttpRequestMessageConfiguration>(NuGetConfigurationKey), configuration);
#else
            request.Properties[NuGetConfigurationKey] = configuration;
#endif
        }
Exemple #3
0
        /// <summary>
        /// Creates an instance of <see cref="HttpRequestMessage"/>.
        /// </summary>
        /// <param name="method">Desired HTTP verb</param>
        /// <param name="requestUri">Request URI</param>
        /// <param name="configuration">The request configuration</param>
        /// <returns>Instance of <see cref="HttpRequestMessage"/></returns>
        public static HttpRequestMessage Create(
            HttpMethod method,
            Uri requestUri,
            HttpRequestMessageConfiguration configuration)
        {
            if (requestUri == null)
            {
                throw new ArgumentNullException(nameof(requestUri));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var request = new HttpRequestMessage(method, requestUri);

            request.SetConfiguration(configuration);

            return(request);
        }
Exemple #4
0
        /// <summary>
        /// Attaches an HTTP request configuration instance to the given message as custom property.
        /// If the configuration has already been set on the request message, the old configuration
        /// is replaced.
        /// </summary>
        /// <param name="request">The HTTP request message.</param>
        /// <param name="configuration">An HTTP request message configuration instance.</param>
        public static void SetConfiguration(this HttpRequestMessage request, HttpRequestMessageConfiguration configuration)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

#if USE_HTTPREQUESTMESSAGE_OPTIONS
            request.Options.Set(new HttpRequestOptionsKey <HttpRequestMessageConfiguration>(NuGetConfigurationKey), configuration);
#else
            // stop ignoring CS0618 when fixing https://github.com/NuGet/Home/issues/9981
#pragma warning disable CS0618
            request.Properties[NuGetConfigurationKey] = configuration;
#pragma warning restore CS0618
#endif
        }