From b1d8aa0b6418a4edba8ce3b7b6f3db78616fd523 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Tue, 25 Mar 2014 16:20:21 +0200 Subject: Use the "Content-Encoding" header to indicate gzipped streams --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 2 +- OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs | 2 +- OpenSim/Framework/WebUtil.cs | 8 +++++--- OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | 19 ++++++++----------- 4 files changed, 15 insertions(+), 16 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index ea7f195..2f7b549 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -833,7 +833,7 @@ namespace OpenSim.Framework.Servers.HttpServer 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); using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8)) diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs index 3171759..f36cbbc 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs @@ -181,7 +181,7 @@ namespace OpenSim.Framework.Servers.HttpServer _request = req; _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"]); if (null != req.Headers["content-type"]) _contentType = _request.Headers["content-type"]; diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 10a2560..3972c06 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -250,9 +250,12 @@ namespace OpenSim.Framework byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); + request.ContentType = "application/json"; + if (compressed) { - request.ContentType = "application/x-gzip"; + request.Headers["Content-Encoding"] = "gzip"; + using (MemoryStream ms = new MemoryStream()) { using (GZipStream comp = new GZipStream(ms, CompressionMode.Compress)) @@ -270,10 +273,9 @@ namespace OpenSim.Framework } else { - request.ContentType = "application/json"; request.ContentLength = buffer.Length; //Count bytes to send using (Stream requestStream = request.GetRequestStream()) - requestStream.Write(buffer, 0, buffer.Length); //Send it + requestStream.Write(buffer, 0, buffer.Length); //Send it } } diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 4ac477f..1254df4 100644 --- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs @@ -232,17 +232,16 @@ namespace OpenSim.Server.Handlers.Simulation httpResponse.KeepAlive = false; Encoding encoding = Encoding.UTF8; - Stream inputStream = null; - if (httpRequest.ContentType == "application/x-gzip") - inputStream = new GZipStream(request, CompressionMode.Decompress); - else if (httpRequest.ContentType == "application/json") - inputStream = request; - else // no go + if (httpRequest.ContentType != "application/json") { httpResponse.StatusCode = 406; 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); string requestBody = reader.ReadToEnd(); @@ -433,11 +432,9 @@ namespace OpenSim.Server.Handlers.Simulation keysvals.Add("headers", headervals); keysvals.Add("querystringkeys", querystringkeys); - Stream inputStream; - if (httpRequest.ContentType == "application/x-gzip") - inputStream = new GZipStream(request, CompressionMode.Decompress); - else - inputStream = request; + Stream inputStream = request; + if (httpRequest.Headers["Content-Encoding"] == "gzip") + inputStream = new GZipStream(inputStream, CompressionMode.Decompress); Encoding encoding = Encoding.UTF8; StreamReader reader = new StreamReader(inputStream, encoding); -- cgit v1.1