From e86bd042bb06fcc09c38088f3c08bde4cc1c72a2 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 28 Oct 2020 00:09:32 +0000 Subject: [PATCH] dont let webrequests keep copies of all put/post. should not, but may impact some connections like redirection --- OpenSim/Framework/WebUtil.cs | 50 ++++++++++++----------- OpenSim/Region/Application/Application.cs | 2 +- OpenSim/Server/ServerMain.cs | 2 +- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index b49396c6dc..92718569f2 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -212,6 +212,7 @@ namespace OpenSim.Framework request.MaximumAutomaticRedirections = 10; request.ReadWriteTimeout = timeout / 2; request.Headers[OSHeaderRequestID] = reqnum.ToString(); + request.AllowWriteStreamBuffering = false; } catch (Exception ex) { @@ -258,7 +259,7 @@ namespace OpenSim.Framework buffer = null; } - using (WebResponse response = request.GetResponse()) + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { @@ -381,13 +382,14 @@ namespace OpenSim.Framework HttpWebRequest request = null; try { - request = (HttpWebRequest)HttpWebRequest.Create(url); + request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Timeout = timeout; request.KeepAlive = false; request.MaximumAutomaticRedirections = 10; request.ReadWriteTimeout = timeout / 2; request.Headers[OSHeaderRequestID] = reqnum.ToString(); + request.AllowWriteStreamBuffering = false; } catch (Exception ex) { @@ -414,14 +416,14 @@ namespace OpenSim.Framework buffer = null; } - using (WebResponse response = request.GetResponse()) + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string responseStr = reader.ReadToEnd(); rcvlen = responseStr.Length; - if (WebUtil.DebugLevel >= 5) - WebUtil.LogResponseDetail(reqnum, responseStr); + if (DebugLevel >= 5) + LogResponseDetail(reqnum, responseStr); OSD responseOSD = OSDParser.Deserialize(responseStr); if (responseOSD.Type == OSDType.Map) @@ -784,6 +786,8 @@ namespace OpenSim.Framework if (auth != null) auth.AddAuthorization(request.Headers); + request.AllowWriteStreamBuffering = false; + if (maxConnections > 0 && request.ServicePoint.ConnectionLimit < maxConnections) request.ServicePoint.ConnectionLimit = maxConnections; @@ -976,13 +980,14 @@ namespace OpenSim.Framework { request = (HttpWebRequest)WebRequest.Create(requestUrl); request.Method = verb; - request.AllowWriteStreamBuffering = false; if (timeoutsecs > 0) request.Timeout = timeoutsecs * 1000; if(!keepalive) request.KeepAlive = false; if (auth != null) auth.AddAuthorization(request.Headers); + + request.AllowWriteStreamBuffering = false; request.ContentType = "application/x-www-form-urlencoded"; } catch (Exception e) @@ -1079,6 +1084,8 @@ namespace OpenSim.Framework request.KeepAlive = false; if (auth != null) auth.AddAuthorization(request.Headers); + + request.AllowWriteStreamBuffering = false; request.ContentType = "application/x-www-form-urlencoded"; } catch (Exception e) @@ -1225,7 +1232,7 @@ namespace OpenSim.Framework int reqnum = WebUtil.RequestNumber++; if (WebUtil.DebugLevel >= 3) - m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} SynchronousRestObject {1} to {2}", + m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} SRestObjectRequest {1} {2}", reqnum, verb, requestUrl); int tickstart = Util.EnvironmentTickCount(); @@ -1240,24 +1247,21 @@ namespace OpenSim.Framework if (auth != null) auth.AddAuthorization(request.Headers); + request.AllowWriteStreamBuffering = false; + if (pTimeout != 0) request.Timeout = pTimeout; - if (maxConnections > 0 && request.ServicePoint.ConnectionLimit < maxConnections) - request.ServicePoint.ConnectionLimit = maxConnections; - request.AllowWriteStreamBuffering = false; request.Method = verb; } catch (Exception e) { - m_log.DebugFormat("[SynchronousRestObjectRequester]: Exception in creating request {0} {1}: {2}{3}", + m_log.DebugFormat("[SRestObjectRequest]: Exception in creating request {0} {1}: {2}{3}", verb, requestUrl, e.Message, e.StackTrace); return deserial; } - int sendlen = 0; - try { if ((verb == "POST") || (verb == "PUT")) @@ -1275,7 +1279,7 @@ namespace OpenSim.Framework data = ms.ToArray(); } - sendlen = data.Length; + int sendlen = data.Length; request.ContentLength = sendlen; if (WebUtil.DebugLevel >= 5) @@ -1289,7 +1293,7 @@ namespace OpenSim.Framework catch (Exception e) { m_log.DebugFormat( - "[SynchronousRestObjectRequester]: Exception in making request {0} {1}: {2}{3}", + "[SRestObjectRequest]: Exception in making request {0} {1}: {2}{3}", verb, requestUrl, e.Message, e.StackTrace); return deserial; @@ -1312,7 +1316,7 @@ namespace OpenSim.Framework } else { - m_log.DebugFormat("[SynchronousRestObjectRequester]: Oops! no content found in response stream from {0} {1}", + m_log.DebugFormat("[SRestObjectRequest]: Oops! no content found in response stream from {0} {1}", verb, requestUrl); } } @@ -1325,38 +1329,38 @@ namespace OpenSim.Framework { if (hwr.StatusCode == HttpStatusCode.Unauthorized) { - m_log.ErrorFormat("[SynchronousRestObjectRequester]: Web request {0} requires authentication", + m_log.ErrorFormat("[SRestObjectRequest]: {0} requires authentication", requestUrl); } else if(hwr.StatusCode != HttpStatusCode.NotFound) { - m_log.WarnFormat("[SynchronousRestObjectRequester]: Web request {0} returned error: {1}", + m_log.WarnFormat("[SRestObjectRequest]: {0} returned error: {1}", requestUrl, hwr.StatusCode); } } else m_log.ErrorFormat( - "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} {3}", + "[SRestObjectRequest]: WebException for {0} {1} {2} {3}", verb, requestUrl, typeof(TResponse).ToString(), e.Message); } } catch (System.InvalidOperationException) { // This is what happens when there is invalid XML - m_log.DebugFormat("[SynchronousRestObjectRequester]: Invalid XML from {0} {1} {2}", + m_log.DebugFormat("[SRestObjectRequest]: Invalid XML from {0} {1} {2}", verb, requestUrl, typeof(TResponse).ToString()); } catch (Exception e) { - m_log.DebugFormat("[SynchronousRestObjectRequester]: Exception on response from {0} {1}: {2}", + m_log.DebugFormat("[SRestObjectRequest]: Exception on response from {0} {1}: {2}", verb, requestUrl, e.Message); } int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); if (tickdiff > WebUtil.LongCallTime) { - m_log.InfoFormat("[LOGHTTP]: Slow SynchronousRestObject request {0} {1} to {2} took {3}ms, {4}/{5}bytes", - reqnum, verb, requestUrl, tickdiff, sendlen, rcvlen); + m_log.InfoFormat("[LOGHTTP]: Slow SRestObjectRequest {0} {1} {2} took {3}ms, {4}bytes", + reqnum, verb, requestUrl, tickdiff, rcvlen); } else if (WebUtil.DebugLevel >= 4) { diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs index 14fe7c0f5a..1c3b603465 100644 --- a/OpenSim/Region/Application/Application.cs +++ b/OpenSim/Region/Application/Application.cs @@ -80,7 +80,7 @@ namespace OpenSim ServicePointManager.MaxServicePointIdleTime = 30000; try { ServicePointManager.DnsRefreshTimeout = 5000; } catch { } - ServicePointManager.Expect100Continue = false; + ServicePointManager.Expect100Continue = true; // needed now to suport auto redir without writecache ServicePointManager.UseNagleAlgorithm = false; // Add the arguments supplied when running the application to the configuration diff --git a/OpenSim/Server/ServerMain.cs b/OpenSim/Server/ServerMain.cs index fffedae5ca..41844c09b8 100644 --- a/OpenSim/Server/ServerMain.cs +++ b/OpenSim/Server/ServerMain.cs @@ -83,7 +83,7 @@ namespace OpenSim.Server ServicePointManager.DefaultConnectionLimit = 32; ServicePointManager.MaxServicePointIdleTime = 30000; - ServicePointManager.Expect100Continue = false; + ServicePointManager.Expect100Continue = true; // needed now to suport auto redir without writecache ServicePointManager.UseNagleAlgorithm = false; ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;