<commit_before>﻿using System;
using System.IO;
using System.Net;
using System.Text;
using Sugar.Mime;

namespace Sugar.Net
{
    /// <summary>
    /// Class to download content from the internet
    /// </summary>
    public class HttpService : IHttpService
    {
        /// <summary>
        /// Maps the specified <see cref="WebResponse"/> to the given <see cref="HttpResponse"/>.
        /// </summary>
        /// <param name="webResponse">The web response.</param>
        /// <param name="response">The HTTP response.</param>
        /// <returns>the given HTTP response.</returns>
        public static HttpResponse Map(WebResponse webResponse, HttpResponse response)
        {
            response.ContentLength = webResponse.ContentLength;

            foreach (string header in webResponse.Headers)
            {
                response.Headers.Add(header, webResponse.Headers[header]);
            }

            var httpWebResponse = webResponse as HttpWebResponse;
            if (httpWebResponse != null)
            {
                response.StatusCode = httpWebResponse.StatusCode;
                response.StatusDescription = httpWebResponse.StatusDescription;
            }

            return response;
        }

        /// <summary>
        /// Downloads the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        private static HttpResponse InternalDownload(HttpRequest request)
        {
            var result = new HttpResponse
                             {
                                 Url = request.Url,
                                 UserAgent = request.UserAgent
                             };

            var webRequest = request.ToWebRequest();
<commit_msg>Fix for Map function when webResponse is null.<commit_after>﻿using System;
using System.IO;
using System.Net;
using System.Text;
using Sugar.Mime;

namespace Sugar.Net
{
    /// <summary>
    /// Class to download content from the internet
    /// </summary>
    public class HttpService : IHttpService
    {
        /// <summary>
        /// Maps the specified <see cref="WebResponse"/> to the given <see cref="HttpResponse"/>.
        /// </summary>
        /// <param name="webResponse">The web response.</param>
        /// <param name="response">The HTTP response.</param>
        /// <returns>the given HTTP response.</returns>
        public static HttpResponse Map(WebResponse webResponse, HttpResponse response)
        {
            if (webResponse != null)
            {
                response.ContentLength = webResponse.ContentLength;

                foreach (string header in webResponse.Headers)
                {
                    response.Headers.Add(header, webResponse.Headers[header]);
                }

                var httpWebResponse = webResponse as HttpWebResponse;
                if (httpWebResponse != null)
                {
                    response.StatusCode = httpWebResponse.StatusCode;
                    response.StatusDescription = httpWebResponse.StatusDescription;
                }
            }

            return response;
        }

        /// <summary>
        /// Downloads the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        private static HttpResponse InternalDownload(HttpRequest request)
        {
            var result = new HttpResponse
                             {
                                 Url = request.Url,
                                 UserAgent = request.UserAgent
                             };

            var webRequest = request.ToWebRequest();

{'fraction_non_alphanumeric': 0.1005933117583603, 'fraction_numerical': 0.0, 'mean_word_length': 1.5703395703395704, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5262588', 'n_tokens_mistral': 850, 'n_tokens_neox': 825, 'n_words': 220}