internal static HttpRequestMessage CreateBufferedCopy(this HttpRequestMessage httpRequestMessage)
        {
            Fx.Assert(httpRequestMessage != null, "The 'httpRequestMessage' parameter should never be null.");

            HttpRequestMessage bufferedHttpRequestMessage = new HttpRequestMessage();

            bufferedHttpRequestMessage.RequestUri = httpRequestMessage.RequestUri != null ? new Uri(httpRequestMessage.RequestUri, string.Empty) : null;
            bufferedHttpRequestMessage.Method     = httpRequestMessage.Method != null ? new HttpMethod(httpRequestMessage.Method.Method) : null;
            bufferedHttpRequestMessage.Version    = (Version)(httpRequestMessage.Version != null ? httpRequestMessage.Version.Clone() : null);

            foreach (KeyValuePair <string, IEnumerable <string> > header in httpRequestMessage.Headers)
            {
                bufferedHttpRequestMessage.Headers.AddHeaderWithoutValidation(header);
            }

            foreach (KeyValuePair <string, object> header in httpRequestMessage.Properties)
            {
                IMessageProperty messageProperty = header.Value as IMessageProperty;
                object           value           = messageProperty != null?
                                                   messageProperty.CreateCopy() :
                                                       header.Value;

                bufferedHttpRequestMessage.Properties.Add(header.Key, value);
            }

            bufferedHttpRequestMessage.Content = CreateBufferedCopyOfContent(httpRequestMessage.Content);

            return(bufferedHttpRequestMessage);
        }
        private object CreateCopyOfPropertyValue(object propertyValue)
        {
            IMessageProperty property = propertyValue as IMessageProperty;

            if (property == null)
            {
                return(propertyValue);
            }
            object obj2 = property.CreateCopy();

            if (obj2 == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("MessagePropertyReturnedNullCopy")));
            }
            return(obj2);
        }
예제 #3
0
        private object CreateCopyOfPropertyValue(object propertyValue)
        {
            IMessageProperty messageProperty = propertyValue as IMessageProperty;

            if (messageProperty == null)
            {
                return(propertyValue);
            }
            object copy = messageProperty.CreateCopy();

            if (copy == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.MessagePropertyReturnedNullCopy));
            }
            return(copy);
        }
예제 #4
0
    public static void CreateCopy_Copies_Properties()
    {
        const string testKeyName = "testKey";

        HttpRequestMessageProperty original = new HttpRequestMessageProperty();

        // Set properties to other than default ctor to verify default ctor is not used
        original.QueryString          = "name=Fred";
        original.Method               = "GET";
        original.SuppressEntityBody   = true;
        original.Headers[testKeyName] = "testValue";

        IMessageProperty copyMessageProperty = ((IMessageProperty)original).CreateCopy();

        Assert.IsType <HttpRequestMessageProperty>(copyMessageProperty);
        HttpRequestMessageProperty copy = (HttpRequestMessageProperty)copyMessageProperty;

        Assert.Equal <string>(original.QueryString, copy.QueryString);
        Assert.Equal <string>(original.Method, copy.Method);
        Assert.Equal <bool>(original.SuppressEntityBody, copy.SuppressEntityBody);
        Assert.Equal <int>(original.Headers.Count, copy.Headers.Count);
        Assert.Equal <string>(original.Headers[testKeyName], copy.Headers[testKeyName]);
    }