Use the "Content-Encoding" header to indicate gzipped streams

0.8.0.3
Oren Hurvitz 2014-03-25 16:20:21 +02:00
parent 8ecab21b37
commit b1d8aa0b64
4 changed files with 15 additions and 16 deletions

View File

@ -833,7 +833,7 @@ namespace OpenSim.Framework.Servers.HttpServer
Stream inputStream = Util.Copy(request.InputStream); Stream inputStream = Util.Copy(request.InputStream);
if (request.ContentType == "application/x-gzip") if (request.Headers["Content-Encoding"] == "gzip")
inputStream = new GZipStream(inputStream, System.IO.Compression.CompressionMode.Decompress); inputStream = new GZipStream(inputStream, System.IO.Compression.CompressionMode.Decompress);
using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8)) using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8))

View File

@ -181,7 +181,7 @@ namespace OpenSim.Framework.Servers.HttpServer
_request = req; _request = req;
_context = context; _context = context;
if (null != req.Headers["content-encoding"]) if ((null != req.Headers["content-encoding"]) && ("gzip" != req.Headers["content-encoding"]))
_contentEncoding = Encoding.GetEncoding(_request.Headers["content-encoding"]); _contentEncoding = Encoding.GetEncoding(_request.Headers["content-encoding"]);
if (null != req.Headers["content-type"]) if (null != req.Headers["content-type"])
_contentType = _request.Headers["content-type"]; _contentType = _request.Headers["content-type"];

View File

@ -250,9 +250,12 @@ namespace OpenSim.Framework
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
request.ContentType = "application/json";
if (compressed) if (compressed)
{ {
request.ContentType = "application/x-gzip"; request.Headers["Content-Encoding"] = "gzip";
using (MemoryStream ms = new MemoryStream()) using (MemoryStream ms = new MemoryStream())
{ {
using (GZipStream comp = new GZipStream(ms, CompressionMode.Compress)) using (GZipStream comp = new GZipStream(ms, CompressionMode.Compress))
@ -270,10 +273,9 @@ namespace OpenSim.Framework
} }
else else
{ {
request.ContentType = "application/json";
request.ContentLength = buffer.Length; //Count bytes to send request.ContentLength = buffer.Length; //Count bytes to send
using (Stream requestStream = request.GetRequestStream()) using (Stream requestStream = request.GetRequestStream())
requestStream.Write(buffer, 0, buffer.Length); //Send it requestStream.Write(buffer, 0, buffer.Length); //Send it
} }
} }

View File

@ -232,17 +232,16 @@ namespace OpenSim.Server.Handlers.Simulation
httpResponse.KeepAlive = false; httpResponse.KeepAlive = false;
Encoding encoding = Encoding.UTF8; Encoding encoding = Encoding.UTF8;
Stream inputStream = null; if (httpRequest.ContentType != "application/json")
if (httpRequest.ContentType == "application/x-gzip")
inputStream = new GZipStream(request, CompressionMode.Decompress);
else if (httpRequest.ContentType == "application/json")
inputStream = request;
else // no go
{ {
httpResponse.StatusCode = 406; httpResponse.StatusCode = 406;
return encoding.GetBytes("false"); return encoding.GetBytes("false");
} }
Stream inputStream = request;
if (httpRequest.Headers["Content-Encoding"] == "gzip")
inputStream = new GZipStream(inputStream, CompressionMode.Decompress);
StreamReader reader = new StreamReader(inputStream, encoding); StreamReader reader = new StreamReader(inputStream, encoding);
string requestBody = reader.ReadToEnd(); string requestBody = reader.ReadToEnd();
@ -433,11 +432,9 @@ namespace OpenSim.Server.Handlers.Simulation
keysvals.Add("headers", headervals); keysvals.Add("headers", headervals);
keysvals.Add("querystringkeys", querystringkeys); keysvals.Add("querystringkeys", querystringkeys);
Stream inputStream; Stream inputStream = request;
if (httpRequest.ContentType == "application/x-gzip") if (httpRequest.Headers["Content-Encoding"] == "gzip")
inputStream = new GZipStream(request, CompressionMode.Decompress); inputStream = new GZipStream(inputStream, CompressionMode.Decompress);
else
inputStream = request;
Encoding encoding = Encoding.UTF8; Encoding encoding = Encoding.UTF8;
StreamReader reader = new StreamReader(inputStream, encoding); StreamReader reader = new StreamReader(inputStream, encoding);