internal static async Task<HttpRequestMessage> ConvertRtRequestMessageToNet(rt.HttpRequestMessage message, CancellationToken token)
        {
            var req = new HttpRequestMessage()
            {
                Method = new HttpMethod(message.Method.Method),
                RequestUri = message.RequestUri,
                Content = await GetNetContentFromRt(message.Content, token).ConfigureAwait(false),
            };

            foreach (var header in message.Headers)
                req.Headers.TryAddWithoutValidation(header.Key, header.Value);

            foreach (var prop in message.Properties)
                req.Properties.Add(prop);

            return req;
        }
 internal static Version GetVersionFromEnum(rt.HttpVersion version)
 {
     switch (version)
     {
         case rt.HttpVersion.None:
             return NoVersion;
             break;
         case rt.HttpVersion.Http10:
             return Version10;
             break;
         case rt.HttpVersion.Http11:
             return Version11;
             break;
         default:
             throw new ArgumentOutOfRangeException("version");
     }
 }
        internal static async Task<HttpContent> GetNetContentFromRt(rt.IHttpContent content, CancellationToken token)
        {
            if (content == null)
                return null;

            var str = await content.ReadAsInputStreamAsync().AsTask(token).ConfigureAwait(false);

            var c = new StreamContent(str.AsStreamForRead());

            foreach (var header in content.Headers)
                c.Headers.TryAddWithoutValidation(header.Key, header.Value);

            return c;
        }
        internal static async Task<HttpResponseMessage> ConvertRtResponseMessageToNet(rt.HttpResponseMessage message, CancellationToken token)
        {
            var resp = new HttpResponseMessage((HttpStatusCode)(int)message.StatusCode)
            {
                ReasonPhrase = message.ReasonPhrase,
                RequestMessage = await ConvertRtRequestMessageToNet(message.RequestMessage, token).ConfigureAwait(false),
                Content = await GetNetContentFromRt(message.Content, token).ConfigureAwait(false),
                Version = GetVersionFromEnum(message.Version),
            };

            foreach (var header in message.Headers)
                resp.Headers.TryAddWithoutValidation(header.Key, header.Value);

            return resp;
        }
 internal static Version GetVersionFromEnum(rt.HttpVersion version)
 {
     int iVersion = (int)version;
     switch (iVersion)
     {
         case 0:
             return NoVersion;
         case 1:
             return Version10;
         case 2:
             return Version11;
         case 3:
             return Version20;
         default:
             throw new ArgumentOutOfRangeException("version");
     }
 }