diff options
author | UbitUmarov | 2016-12-30 07:15:28 +0000 |
---|---|---|
committer | UbitUmarov | 2016-12-30 07:15:28 +0000 |
commit | 5fc36059552231ac5f79592f7d1845643dd89524 (patch) | |
tree | 53c2a92c5bc35f9711267f993c41e9d6da94a76b /OpenSim | |
parent | Merge branch 'master' into httptests (diff) | |
download | opensim-SC-5fc36059552231ac5f79592f7d1845643dd89524.zip opensim-SC-5fc36059552231ac5f79592f7d1845643dd89524.tar.gz opensim-SC-5fc36059552231ac5f79592f7d1845643dd89524.tar.bz2 opensim-SC-5fc36059552231ac5f79592f7d1845643dd89524.tar.xz |
some cleanup, use more using(), more checks so http request mem stream is closed
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 69 |
1 files changed, 27 insertions, 42 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index d7e5123..9c6ee9c 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |||
@@ -529,14 +529,10 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
529 | if (psEvArgs.Request != null) | 529 | if (psEvArgs.Request != null) |
530 | { | 530 | { |
531 | OSHttpRequest req = new OSHttpRequest(context, request); | 531 | OSHttpRequest req = new OSHttpRequest(context, request); |
532 | 532 | string requestBody = String.Empty; | |
533 | Stream requestStream = req.InputStream; | ||
534 | |||
535 | Encoding encoding = Encoding.UTF8; | 533 | Encoding encoding = Encoding.UTF8; |
536 | StreamReader reader = new StreamReader(requestStream, encoding); | 534 | using(StreamReader reader = new StreamReader(req.InputStream, encoding)) |
537 | 535 | requestBody = reader.ReadToEnd(); | |
538 | string requestBody = reader.ReadToEnd(); | ||
539 | reader.Close(); | ||
540 | 536 | ||
541 | Hashtable keysvals = new Hashtable(); | 537 | Hashtable keysvals = new Hashtable(); |
542 | Hashtable headervals = new Hashtable(); | 538 | Hashtable headervals = new Hashtable(); |
@@ -630,6 +626,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
630 | byte[] buffer500 = SendHTML500(response); | 626 | byte[] buffer500 = SendHTML500(response); |
631 | response.OutputStream.Write(buffer500, 0, buffer500.Length); | 627 | response.OutputStream.Write(buffer500, 0, buffer500.Length); |
632 | response.Send(); | 628 | response.Send(); |
629 | if(request.InputStream.CanRead) | ||
630 | request.InputStream.Close(); | ||
633 | } | 631 | } |
634 | catch | 632 | catch |
635 | { | 633 | { |
@@ -674,7 +672,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
674 | // } | 672 | // } |
675 | // } | 673 | // } |
676 | 674 | ||
677 | //response.KeepAlive = true; | ||
678 | response.SendChunked = false; | 675 | response.SendChunked = false; |
679 | 676 | ||
680 | string path = request.RawUrl; | 677 | string path = request.RawUrl; |
@@ -698,15 +695,10 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
698 | { | 695 | { |
699 | //m_log.Debug("[BASE HTTP SERVER]: Found Caps based HTTP Handler"); | 696 | //m_log.Debug("[BASE HTTP SERVER]: Found Caps based HTTP Handler"); |
700 | IGenericHTTPHandler HTTPRequestHandler = requestHandler as IGenericHTTPHandler; | 697 | IGenericHTTPHandler HTTPRequestHandler = requestHandler as IGenericHTTPHandler; |
701 | Stream requestStream = request.InputStream; | 698 | string requestBody = String.Empty; |
702 | |||
703 | Encoding encoding = Encoding.UTF8; | 699 | Encoding encoding = Encoding.UTF8; |
704 | StreamReader reader = new StreamReader(requestStream, encoding); | 700 | using(StreamReader reader = new StreamReader(request.InputStream, encoding)) |
705 | 701 | requestBody = reader.ReadToEnd(); | |
706 | string requestBody = reader.ReadToEnd(); | ||
707 | |||
708 | reader.Close(); | ||
709 | //requestStream.Close(); | ||
710 | 702 | ||
711 | Hashtable keysvals = new Hashtable(); | 703 | Hashtable keysvals = new Hashtable(); |
712 | Hashtable headervals = new Hashtable(); | 704 | Hashtable headervals = new Hashtable(); |
@@ -746,7 +738,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
746 | else | 738 | else |
747 | { | 739 | { |
748 | IStreamHandler streamHandler = (IStreamHandler)requestHandler; | 740 | IStreamHandler streamHandler = (IStreamHandler)requestHandler; |
749 | |||
750 | using (MemoryStream memoryStream = new MemoryStream()) | 741 | using (MemoryStream memoryStream = new MemoryStream()) |
751 | { | 742 | { |
752 | streamHandler.Handle(path, request.InputStream, memoryStream, request, response); | 743 | streamHandler.Handle(path, request.InputStream, memoryStream, request, response); |
@@ -823,8 +814,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
823 | } | 814 | } |
824 | } | 815 | } |
825 | 816 | ||
826 | request.InputStream.Close(); | ||
827 | |||
828 | if (buffer != null) | 817 | if (buffer != null) |
829 | { | 818 | { |
830 | if (WebUtil.DebugLevel >= 5) | 819 | if (WebUtil.DebugLevel >= 5) |
@@ -856,10 +845,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
856 | requestEndTick = Environment.TickCount; | 845 | requestEndTick = Environment.TickCount; |
857 | 846 | ||
858 | response.Send(); | 847 | response.Send(); |
859 | |||
860 | //response.OutputStream.Close(); | ||
861 | |||
862 | //response.FreeContext(); | ||
863 | } | 848 | } |
864 | catch (SocketException e) | 849 | catch (SocketException e) |
865 | { | 850 | { |
@@ -891,6 +876,9 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
891 | } | 876 | } |
892 | finally | 877 | finally |
893 | { | 878 | { |
879 | if(request.InputStream.CanRead) | ||
880 | request.InputStream.Close(); | ||
881 | |||
894 | // Every month or so this will wrap and give bad numbers, not really a problem | 882 | // Every month or so this will wrap and give bad numbers, not really a problem |
895 | // since its just for reporting | 883 | // since its just for reporting |
896 | int tickdiff = requestEndTick - requestStartTick; | 884 | int tickdiff = requestEndTick - requestStartTick; |
@@ -1148,9 +1136,10 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1148 | } | 1136 | } |
1149 | finally | 1137 | finally |
1150 | { | 1138 | { |
1151 | if (innerStream != null) | 1139 | if (innerStream != null && innerStream.CanRead) |
1152 | innerStream.Dispose(); | 1140 | innerStream.Dispose(); |
1153 | requestStream.Dispose(); | 1141 | if (requestStream.CanRead) |
1142 | requestStream.Dispose(); | ||
1154 | } | 1143 | } |
1155 | 1144 | ||
1156 | //m_log.Debug(requestBody); | 1145 | //m_log.Debug(requestBody); |
@@ -1407,15 +1396,15 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1407 | //m_log.Warn("[BASE HTTP SERVER]: We've figured out it's a LLSD Request"); | 1396 | //m_log.Warn("[BASE HTTP SERVER]: We've figured out it's a LLSD Request"); |
1408 | Stream requestStream = request.InputStream; | 1397 | Stream requestStream = request.InputStream; |
1409 | 1398 | ||
1399 | string requestBody = string.Empty; | ||
1410 | Encoding encoding = Encoding.UTF8; | 1400 | Encoding encoding = Encoding.UTF8; |
1411 | StreamReader reader = new StreamReader(requestStream, encoding); | 1401 | using(StreamReader reader = new StreamReader(requestStream,encoding)) |
1402 | requestBody = reader.ReadToEnd(); | ||
1412 | 1403 | ||
1413 | string requestBody = reader.ReadToEnd(); | 1404 | if(requestStream.CanRead) |
1414 | reader.Close(); | 1405 | requestStream.Close(); |
1415 | requestStream.Close(); | ||
1416 | 1406 | ||
1417 | //m_log.DebugFormat("[OGP]: {0}:{1}", request.RawUrl, requestBody); | 1407 | //m_log.DebugFormat("[OGP]: {0}:{1}", request.RawUrl, requestBody); |
1418 | response.KeepAlive = true; | ||
1419 | 1408 | ||
1420 | OSD llsdRequest = null; | 1409 | OSD llsdRequest = null; |
1421 | OSD llsdResponse = null; | 1410 | OSD llsdResponse = null; |
@@ -1736,15 +1725,12 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1736 | byte[] buffer; | 1725 | byte[] buffer; |
1737 | 1726 | ||
1738 | Stream requestStream = request.InputStream; | 1727 | Stream requestStream = request.InputStream; |
1739 | 1728 | string requestBody = string.Empty; | |
1740 | Encoding encoding = Encoding.UTF8; | 1729 | Encoding encoding = Encoding.UTF8; |
1741 | StreamReader reader = new StreamReader(requestStream, encoding); | 1730 | using(StreamReader reader = new StreamReader(requestStream,encoding)) |
1742 | 1731 | requestBody = reader.ReadToEnd(); | |
1743 | string requestBody = reader.ReadToEnd(); | 1732 | if(requestStream.CanRead) |
1744 | // avoid warning for now | 1733 | requestStream.Close(); |
1745 | reader.ReadToEnd(); | ||
1746 | reader.Close(); | ||
1747 | requestStream.Close(); | ||
1748 | 1734 | ||
1749 | Hashtable keysvals = new Hashtable(); | 1735 | Hashtable keysvals = new Hashtable(); |
1750 | Hashtable headervals = new Hashtable(); | 1736 | Hashtable headervals = new Hashtable(); |
@@ -2283,10 +2269,9 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
2283 | string file = Path.Combine(".", "http_500.html"); | 2269 | string file = Path.Combine(".", "http_500.html"); |
2284 | if (!File.Exists(file)) | 2270 | if (!File.Exists(file)) |
2285 | return getDefaultHTTP500(); | 2271 | return getDefaultHTTP500(); |
2286 | 2272 | string result = string.Empty; | |
2287 | StreamReader sr = File.OpenText(file); | 2273 | using(StreamReader sr = File.OpenText(file)) |
2288 | string result = sr.ReadToEnd(); | 2274 | result = sr.ReadToEnd(); |
2289 | sr.Close(); | ||
2290 | return result; | 2275 | return result; |
2291 | } | 2276 | } |
2292 | 2277 | ||