Fix for SF-3072580 and ensure UTF-8 encoding is used instead of ASCII.

Thanks to Akkarin Dryke for the 3072580 fix.
This commit is contained in:
Ima Mechanique 2012-04-05 18:03:19 +01:00
parent 82287f9eed
commit a442da2ba8
2 changed files with 32 additions and 6 deletions

View file

@ -42,6 +42,8 @@
// ******** // ********
// */ // */
using System; using System;
using System.IO;
using System.IO.Compression;
using System.Net; using System.Net;
using System.Text; using System.Text;
@ -63,7 +65,7 @@ namespace LSLEditor
public static void Request(WebProxy proxy, SecondLife secondlife, string strUrl, SecondLife.list parameters, string postData, SecondLife.key key) public static void Request(WebProxy proxy, SecondLife secondlife, string strUrl, SecondLife.list parameters, string postData, SecondLife.key key)
{ {
string strMethod = "GET"; string strMethod = "GET";
string strContentType = "text/plain;charset=utf-8"; string strContentType = "text/plain; charset=utf-8";
for (int intI = 0; intI < parameters.Count; intI += 2) for (int intI = 0; intI < parameters.Count; intI += 2)
{ {
@ -94,7 +96,7 @@ namespace LSLEditor
wc.Headers.Add("Content-Type", strContentType); wc.Headers.Add("Content-Type", strContentType);
wc.Headers.Add("Accept", "text/*"); wc.Headers.Add("Accept", "text/*");
wc.Headers.Add("Accept-Charset", "utf-8;q=1.0, *;q=0.5"); wc.Headers.Add("Accept-Charset", "utf-8; q=1.0, *; q=0.5");
wc.Headers.Add("Accept-Encoding", "deflate, gzip"); wc.Headers.Add("Accept-Encoding", "deflate, gzip");
wc.Headers.Add("User-Agent", "Second Life LSL/1.19.0(12345) (http://secondlife.com)"); wc.Headers.Add("User-Agent", "Second Life LSL/1.19.0(12345) (http://secondlife.com)");
@ -172,7 +174,9 @@ namespace LSLEditor
else else
{ {
if (e.Result != null) if (e.Result != null)
strResult = Encoding.ASCII.GetString(e.Result); {
strResult = Encoding.UTF8.GetString(e.Result);
}
} }
userState.secondlife.host.ExecuteSecondLife("http_response", userState.httpkey, (SecondLife.integer)intStatusCode, new SecondLife.list(), (SecondLife.String)strResult); userState.secondlife.host.ExecuteSecondLife("http_response", userState.httpkey, (SecondLife.integer)intStatusCode, new SecondLife.list(), (SecondLife.String)strResult);
} }
@ -194,10 +198,22 @@ namespace LSLEditor
else else
{ {
if (e.Result != null) if (e.Result != null)
strResult = Encoding.ASCII.GetString(e.Result); {
string strEncoding = ((System.Net.WebClient)sender).ResponseHeaders["Content-Encoding"];
if (strEncoding == "gzip")
{
GZipStream tempE = new GZipStream(new System.IO.MemoryStream(e.Result), CompressionMode.Decompress);
var sr = new StreamReader(tempE);
strResult = sr.ReadToEnd();
}
else
{
strResult = Encoding.UTF8.GetString(e.Result);
}
}
} }
userState.secondlife.host.ExecuteSecondLife("http_response", userState.httpkey, (SecondLife.integer)intStatusCode, new SecondLife.list(), (SecondLife.String)strResult); userState.secondlife.host.ExecuteSecondLife("http_response", userState.httpkey, (SecondLife.integer)intStatusCode, new SecondLife.list(), (SecondLife.String)strResult);
} }
} }
} }

View file

@ -7,9 +7,19 @@
</head> </head>
<body style="background-color: white; font-family: Verdana, sans-serif;font-size: 13px;line-height: 1.3"> <body style="background-color: white; font-family: Verdana, sans-serif;font-size: 13px;line-height: 1.3">
<div> <div>
<div>
<h3><span class="date"><2012-04-00</span> - Release 2.46.0</h3>
<div>
* Fixed:
<ul>
<li>SF ID: 3072580 - HTTP Request response returned gzip compressed string. (Thanks to Akkarin Dryke).</li>
<li>Also fixed HTTP Request response returning UTF-8 (instead of ASCII).</li>
</ul>
</div>
</div>
<div> <div>
<h3><span class="date">2012-03-18</span> - Release 2.45.1</h3> <h3><span class="date">2012-03-18</span> - Release 2.45.1</h3>
<div>- Fixed: Problem with updater. Our BZip2 decompression code did not work, which prevented the updater creating the new file.</div> <div>* Fixed: Problem with updater. Our BZip2 decompression code did not work, which prevented the updater creating the new file.</div>
</div> </div>
<div> <div>
<h3><span class="date">2012-03-14</span> - Release 2.45.0</h3> <h3><span class="date">2012-03-14</span> - Release 2.45.0</h3>