Esempio n. 1
0
        public static HttpContentType CreateFromBase64(HttpContentHeaderData headerData, string base64)
        {
            var content = CreateBase64(base64);

            content.Headers.ContentType = HttpMediaTypeHeaderValue.Parse(headerData.ContentType);
            return(content);
        }
 public static IHttpContent CreateFromBody(HttpContentHeaderData headerData, string body)
 {
     if (headerData.ContentEncoding == "gzip")
     {
         var content = CreateGzip(body);
         content.Headers.ContentType = new HttpMediaTypeHeaderValue(headerData.ContentType);
         content.Headers.ContentEncoding.ParseAdd(headerData.ContentEncoding);
         return(content);
     }
     else
     {
         var content = CreateString(body);
         content.Headers.ContentType = new HttpMediaTypeHeaderValue(headerData.ContentType);
         return(content);
     }
 }
        private async Task ProcessRequestFromUriAsync(
            int requestId,
            Uri uri,
            HttpContentHeaderData headerData,
            bool useIncrementalUpdates,
            int timeout,
            HttpRequestMessage request,
            string responseType,
            CancellationToken token)
        {
            try
            {
#if WINDOWS_UWP
                var storageFile = await StorageFile.GetFileFromPathAsync(uri.LocalPath).AsTask().ConfigureAwait(false);

                var inputStream = await storageFile.OpenReadAsync().AsTask().ConfigureAwait(false);
#else
                var storageFile = await FileSystem.Current.GetFileFromPathAsync(uri.ToString()).ConfigureAwait(false);

                var input = await storageFile.ReadAllTextAsync().ConfigureAwait(false);

                var byteArray   = Encoding.UTF8.GetBytes(input);
                var inputStream = new MemoryStream(byteArray);
#endif
                request.Content = new HttpStreamContent(inputStream);
                request.Content.Headers.ContentType = new HttpMediaTypeHeaderValue(headerData.ContentType);

                await ProcessRequestAsync(
                    requestId,
                    useIncrementalUpdates,
                    timeout,
                    request,
                    responseType,
                    token).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                if (_shuttingDown)
                {
                    return;
                }

                OnRequestError(requestId, ex.Message, false);
            }
        }
        public static HttpContentType CreateFromBody(HttpContentHeaderData headerData, string body)
        {
            if (headerData.ContentEncoding == "gzip")
            {
                var content = CreateGzip(body);
                content.Headers.ContentType = HttpMediaTypeHeaderValue.Parse(headerData.ContentType);
#if WINDOWS_UWP
                content.Headers.ContentEncoding.ParseAdd(headerData.ContentEncoding);
#else
                content.Headers.ContentEncoding.Add(headerData.ContentEncoding);
#endif
                return(content);
            }
            else
            {
                var content = CreateString(body);
                content.Headers.ContentType = HttpMediaTypeHeaderValue.Parse(headerData.ContentType);
                return(content);
            }
        }
        public static HttpContentHeaderData ExtractHeaders(string[][] headers)
        {
            var result = new HttpContentHeaderData();

            foreach (var header in headers)
            {
                var key = header[0];
                switch (key.ToLowerInvariant())
                {
                case "content-type":
                    result.ContentType = header[1];
                    break;

                case "content-encoding":
                    result.ContentEncoding = header[1];
                    break;

                default:
                    break;
                }
            }

            return(result);
        }