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);
        }
Example #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);
        }