~ubuntu-branches/debian/jessie/banshee-community-extensions/jessie

« back to all changes in this revision

Viewing changes to src/Lyrics/Banshee.Lyrics/Banshee.Lyrics.Network/HttpUtils.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-04-04 18:00:24 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100404180024-z5fwyx9mpp0pm2ss
Tags: 1.6.0-1
* New upstream release
* debian/(control, banshee-extension-appindicator.install):
  + Add Application Indicator package and build-depends (commented out
    because these dependencies are not present in Debian yet)
* debian/copyright:
  + Document more MIT/X11 files in Mirage's source
  + Document LGPL-3 files in Banshee.Telepathy
  + Document bundled NDesk.DBus in Banshee.Telepathy
  + Document Banshee.Lirc copyrights
* debian/rules:
  + --disable-appindicator
* debian/patches/*, debian/control, debian/rules:
  + Drop all patches, applied upstream and/or not needed any more
  + De-quiltify package

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
{
34
34
    public class HttpUtils
35
35
    {
36
 
        public static string ReadHtmlContent (String url)
 
36
        public static string ReadHtmlContent (String url, Encoding encoding)
37
37
        {
38
38
            string html = null;
39
39
              try
40
40
            {
41
 
                html = GetHtml (url);
 
41
                html = GetHtml (url, encoding);
42
42
            } catch (Exception e)
43
43
            {
44
44
                Hyena.Log.DebugFormat ("{0}, {1}", e.Message, url);
47
47
            return html;
48
48
        }
49
49
 
50
 
        private static string GetHtml (string url)
 
50
        private static string GetHtml (string url, Encoding encoding)
51
51
        {
52
52
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);
53
53
            request.Timeout = 6000;
61
61
                }
62
62
            }
63
63
 
64
 
            HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
65
 
            if (response.ContentLength == 0) {
66
 
                return null;
67
 
            }
68
 
 
69
 
            StreamReader reader;
70
 
            if (response.ContentType.Contains ("utf")) {
71
 
                reader = new StreamReader (response.GetResponseStream ());
72
 
            } else {
73
 
                reader = new StreamReader (response.GetResponseStream (), Encoding.GetEncoding ("iso-8859-1"));
74
 
            }
75
 
 
76
 
            //read all bytes from the stream
77
 
            string source = reader.ReadToEnd ();
78
 
            reader.Close ();
79
 
 
80
 
            return source;
 
64
            using (var response = (HttpWebResponse)request.GetResponse ()) {
 
65
                if (response.ContentLength == 0) {
 
66
                    return null;
 
67
                }
 
68
 
 
69
                if (encoding == null) {
 
70
                    if (response.ContentType.Contains ("utf")) {
 
71
                        encoding = Encoding.UTF8;
 
72
                    } else {
 
73
                        encoding = Encoding.GetEncoding ("iso-8859-1");
 
74
                    }
 
75
                }
 
76
 
 
77
                using (var reader = new StreamReader (response.GetResponseStream (), encoding)) {
 
78
                    // Read all bytes from the stream
 
79
                    return reader.ReadToEnd ();
 
80
                }
 
81
            }
81
82
        }
82
83
    }
83
84
}
 
 
b'\\ No newline at end of file'