<commit_before>using System;
using System.IO;
using System.Net;
using Microsoft.SPOT;

namespace netmfazurestorage.Http
{
    /// <summary>
    /// A common helper class for HTTP access to Windows Azure Storage
    /// </summary>
    public static class AzureStorageHttpHelper
    {
        public static BasicHttpResponse SendWebRequest(string url, string authHeader, string dateHeader, string versionHeader, byte[] fileBytes = null, int contentLength = 0, string httpVerb = "GET")
        {
            string responseBody = "";
            HttpStatusCode responseStatusCode = HttpStatusCode.Ambiguous;
            HttpWebRequest request = PrepareRequest(url, authHeader, dateHeader, versionHeader, fileBytes, contentLength, httpVerb);
            try
            {
                HttpWebResponse response;
                using (response = (HttpWebResponse)request.GetResponse())
                {
                    responseStatusCode = response.StatusCode;
                    if (response.StatusCode == HttpStatusCode.Created)
                    {
                        Debug.Print("Asset has been created!");
                    }
                    if (response.StatusCode == HttpStatusCode.Accepted)
                    {
                        Debug.Print("Action has been completed");
                    }
                    if (response.StatusCode == HttpStatusCode.Forbidden)
                    {
                        throw new WebException("Forbidden", null, WebExceptionStatus.ServerProtocolViolation, response);
                    }

                    using (var responseStream = response.GetResponseStream())
                    using (var reader = new StreamReader(responseStream))
                    {
                        char[] bytes = new char[(int)responseStream.Length];

                        if (bytes.Length > 0)
                        {
                            reader.Read(bytes, 0, bytes.Length);

                            responseBody = new string(bytes);
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Conflict)
                {
                    Debug.Print("Asset already exists!");
                }
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Forbidden)
                {
                    Debug.Print("Problem with signature. Check next debug statement for stack");
                }
            }

            Debug.Print(responseBody);
            return new BasicHttpResponse() {Body = responseBody, StatusCode = responseStatusCode};
        }

        /// <summary>
        /// Prepares a HttpWebRequest with required headers of x-ms-date, x-ms-version and Authorization
        /// </summary>
        /// <param name="url"></param>
        /// <param name="authHeader"></param>
        /// <param name="dateHeader"></param>
        /// <param name="versionHeader"></param>
        /// <param name="fileBytes"></param>
        /// <param name="contentLength"></param>
        /// <param name="httpVerb"></param>
        /// <returns></returns>
        private static HttpWebRequest PrepareRequest(string url, string authHeader, string dateHeader, string versionHeader, byte[] fileBytes = null, int contentLength = 0, string httpVerb = "GET")
        {
            var uri = new Uri(url);
            var request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = httpVerb;
            request.ContentLength = contentLength;
            request.Headers.Add("x-ms-date", dateHeader);
            request.Headers.Add("x-ms-version", versionHeader);
            request.Headers.Add("Authorization", authHeader);
            if (contentLength != 0)
            {
                request.GetRequestStream().Write(fileBytes, 0, fileBytes.Length);
            }
            return request;
        }

    }

}<commit_msg>first steps to moving blob client to common library include making the client accept additional headers for blobtype and expect100continue<commit_after>using System;
using System.Collections;
using System.IO;
using System.Net;
using Microsoft.SPOT;

namespace netmfazurestorage.Http
{
    /// <summary>
    /// A common helper class for HTTP access to Windows Azure Storage
    /// </summary>
    public static class AzureStorageHttpHelper
    {
        public static BasicHttpResponse SendWebRequest(string url, string authHeader, string dateHeader, string versionHeader, byte[] fileBytes = null, int contentLength = 0, string httpVerb = "GET", bool expect100Continue = false, Hashtable additionalHeaders = null)
        {
            string responseBody = "";
            HttpStatusCode responseStatusCode = HttpStatusCode.Ambiguous;
            HttpWebRequest request = PrepareRequest(url, authHeader, dateHeader, versionHeader, fileBytes, contentLength, httpVerb, expect100Continue, additionalHeaders);
            try
            {
                HttpWebResponse response;
                using (response = (HttpWebResponse)request.GetResponse())
                {
                    responseStatusCode = response.StatusCode;
                    if (response.StatusCode == HttpStatusCode.Created)
                    {
                        Debug.Print("Asset has been created!");
                    }
                    if (response.StatusCode == HttpStatusCode.Accepted)
                    {
                        Debug.Print("Action has been completed");
                    }
                    if (response.StatusCode == HttpStatusCode.Forbidden)
                    {
                        throw new WebException("Forbidden", null, WebExceptionStatus.ServerProtocolViolation, response);
                    }

                    using (var responseStream = response.GetResponseStream())
                    using (var reader = new StreamReader(responseStream))
                    {
                        char[] bytes = new char[(int)responseStream.Length];

                        if (bytes.Length > 0)
                        {
                            reader.Read(bytes, 0, bytes.Length);

                            responseBody = new string(bytes);
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Conflict)
                {
                    Debug.Print("Asset already exists!");
                }
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Forbidden)
                {
                    Debug.Print("Problem with signature. Check next debug statement for stack");
                }
            }

            Debug.Print(responseBody);
            return new BasicHttpResponse() {Body = responseBody, StatusCode = responseStatusCode};
        }

        /// <summary>
        /// Prepares a HttpWebRequest with required headers of x-ms-date, x-ms-version and Authorization
        /// </summary>
        /// <param name="url"></param>
        /// <param name="authHeader"></param>
        /// <param name="dateHeader"></param>
        /// <param name="versionHeader"></param>
        /// <param name="fileBytes"></param>
        /// <param name="contentLength"></param>
        /// <param name="httpVerb"></param>
        /// <returns></returns>
        private static HttpWebRequest PrepareRequest(string url, string authHeader, string dateHeader, string versionHeader, byte[] fileBytes = null, int contentLength = 0, string httpVerb = "GET", bool expect100Continue = false, Hashtable additionalHeaders = null)
        {
            var uri = new Uri(url);
            var request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = httpVerb;
            request.ContentLength = contentLength;
            request.Headers.Add("x-ms-date", dateHeader);
            request.Headers.Add("x-ms-version", versionHeader);
            request.Headers.Add("Authorization", authHeader);

            if (expect100Continue)
            {
                request.Expect = "100-continue";
            }

            if (additionalHeaders != null)
            {
                foreach (var additionalHeader in additionalHeaders.Keys)
                {
                    request.Headers.Add(additionalHeader.ToString(), additionalHeaders[additionalHeader].ToString());
                }
            }

            if (contentLength != 0)
            {
                request.GetRequestStream().Write(fileBytes, 0, fileBytes.Length);
            }
            return request;
        }

    }

}
{'fraction_non_alphanumeric': 0.097463436928702, 'fraction_numerical': 0.0034277879341864715, 'mean_word_length': 1.640422322775264, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6712810', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1932, 'n_words': 481}