From 6d1d58b6549daea0183b70a1c702e3017abb9663 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Tue, 25 Mar 2014 19:09:03 +0200 Subject: Use the "X-Content-Encoding" header to indicate gzipped data, because old OpenSims fail if they get an unknown "Content-Encoding" --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 5 ++++- OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs | 15 +++++++++++++-- OpenSim/Framework/WebUtil.cs | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 2f7b549..28324a5 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.Headers["Content-Encoding"] == "gzip") + if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip")) inputStream = new GZipStream(inputStream, System.IO.Compression.CompressionMode.Decompress); using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8)) @@ -978,6 +978,9 @@ namespace OpenSim.Framework.Servers.HttpServer { Stream requestStream = request.InputStream; + if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip")) + requestStream = new GZipStream(requestStream, System.IO.Compression.CompressionMode.Decompress); + Encoding encoding = Encoding.UTF8; StreamReader reader = new StreamReader(requestStream, encoding); diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs index f36cbbc..05ec6dc 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs @@ -181,12 +181,23 @@ namespace OpenSim.Framework.Servers.HttpServer _request = req; _context = context; - if ((null != req.Headers["content-encoding"]) && ("gzip" != req.Headers["content-encoding"])) - _contentEncoding = Encoding.GetEncoding(_request.Headers["content-encoding"]); + if (null != req.Headers["content-encoding"]) + { + try + { + _contentEncoding = Encoding.GetEncoding(_request.Headers["content-encoding"]); + } + catch (Exception) + { + // ignore + } + } + if (null != req.Headers["content-type"]) _contentType = _request.Headers["content-type"]; if (null != req.Headers["user-agent"]) _userAgent = req.Headers["user-agent"]; + if (null != req.Headers["remote_addr"]) { try diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 3972c06..eb3633a 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -254,7 +254,7 @@ namespace OpenSim.Framework if (compressed) { - request.Headers["Content-Encoding"] = "gzip"; + request.Headers["X-Content-Encoding"] = "gzip"; // can't set "Content-Encoding" because old OpenSims fail if they get an unrecognized Content-Encoding using (MemoryStream ms = new MemoryStream()) { -- cgit v1.1