diff options
Diffstat (limited to 'OpenSim/Framework/WebUtil.cs')
-rw-r--r-- | OpenSim/Framework/WebUtil.cs | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index e77b88b..4d486e6 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs | |||
@@ -31,6 +31,7 @@ using System.Collections.Generic; | |||
31 | using System.Collections.Specialized; | 31 | using System.Collections.Specialized; |
32 | using System.Globalization; | 32 | using System.Globalization; |
33 | using System.IO; | 33 | using System.IO; |
34 | using System.IO.Compression; | ||
34 | using System.Net; | 35 | using System.Net; |
35 | using System.Net.Security; | 36 | using System.Net.Security; |
36 | using System.Reflection; | 37 | using System.Reflection; |
@@ -142,20 +143,25 @@ namespace OpenSim.Framework | |||
142 | /// </summary> | 143 | /// </summary> |
143 | public static OSDMap PutToService(string url, OSDMap data, int timeout) | 144 | public static OSDMap PutToService(string url, OSDMap data, int timeout) |
144 | { | 145 | { |
145 | return ServiceOSDRequest(url,data, "PUT", timeout); | 146 | return ServiceOSDRequest(url,data, "PUT", timeout, false); |
146 | } | 147 | } |
147 | 148 | ||
148 | public static OSDMap PostToService(string url, OSDMap data, int timeout) | 149 | public static OSDMap PostToService(string url, OSDMap data, int timeout) |
149 | { | 150 | { |
150 | return ServiceOSDRequest(url, data, "POST", timeout); | 151 | return ServiceOSDRequest(url, data, "POST", timeout, false); |
152 | } | ||
153 | |||
154 | public static OSDMap PostToServiceCompressed(string url, OSDMap data, int timeout) | ||
155 | { | ||
156 | return ServiceOSDRequest(url, data, "POST", timeout, true); | ||
151 | } | 157 | } |
152 | 158 | ||
153 | public static OSDMap GetFromService(string url, int timeout) | 159 | public static OSDMap GetFromService(string url, int timeout) |
154 | { | 160 | { |
155 | return ServiceOSDRequest(url, null, "GET", timeout); | 161 | return ServiceOSDRequest(url, null, "GET", timeout, false); |
156 | } | 162 | } |
157 | 163 | ||
158 | public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout) | 164 | public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout, bool compressed) |
159 | { | 165 | { |
160 | int reqnum = m_requestNumber++; | 166 | int reqnum = m_requestNumber++; |
161 | // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); | 167 | // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); |
@@ -180,10 +186,31 @@ namespace OpenSim.Framework | |||
180 | string strBuffer = OSDParser.SerializeJsonString(data); | 186 | string strBuffer = OSDParser.SerializeJsonString(data); |
181 | byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); | 187 | byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); |
182 | 188 | ||
183 | request.ContentType = "application/json"; | 189 | if (compressed) |
184 | request.ContentLength = buffer.Length; //Count bytes to send | 190 | { |
185 | using (Stream requestStream = request.GetRequestStream()) | 191 | request.ContentType = "application/x-gzip"; |
186 | requestStream.Write(buffer, 0, buffer.Length); //Send it | 192 | using (MemoryStream ms = new MemoryStream()) |
193 | { | ||
194 | using (GZipStream comp = new GZipStream(ms, CompressionMode.Compress)) | ||
195 | { | ||
196 | comp.Write(buffer, 0, buffer.Length); | ||
197 | comp.Flush(); | ||
198 | |||
199 | ms.Seek(0, SeekOrigin.Begin); | ||
200 | |||
201 | request.ContentLength = ms.Length; //Count bytes to send | ||
202 | using (Stream requestStream = request.GetRequestStream()) | ||
203 | requestStream.Write(ms.ToArray(), 0, (int)ms.Length); | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | else | ||
208 | { | ||
209 | request.ContentType = "application/json"; | ||
210 | request.ContentLength = buffer.Length; //Count bytes to send | ||
211 | using (Stream requestStream = request.GetRequestStream()) | ||
212 | requestStream.Write(buffer, 0, buffer.Length); //Send it | ||
213 | } | ||
187 | } | 214 | } |
188 | 215 | ||
189 | // capture how much time was spent writing, this may seem silly | 216 | // capture how much time was spent writing, this may seem silly |