aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer
diff options
context:
space:
mode:
authorOren Hurvitz2013-11-28 23:07:14 +0200
committerOren Hurvitz2014-03-25 09:36:53 +0100
commitf901a3820497e0d99accb6f5f60f6517e07c2c8f (patch)
treeced16f5b06d11e2ff109716c0682d27c8d3ed753 /OpenSim/Framework/Servers/HttpServer
parentFixed unit tests due to changes in the threadpool (diff)
downloadopensim-SC-f901a3820497e0d99accb6f5f60f6517e07c2c8f.zip
opensim-SC-f901a3820497e0d99accb6f5f60f6517e07c2c8f.tar.gz
opensim-SC-f901a3820497e0d99accb6f5f60f6517e07c2c8f.tar.bz2
opensim-SC-f901a3820497e0d99accb6f5f60f6517e07c2c8f.tar.xz
Improved logging of HTTP requests
- MemoryBuffer isn't seekable, so we can't log it. Log the string instead. - Handle compressed streams - Don't attempt to dump binary data. Either don't log it at all (if we know it's binary), or at least convert non-ASCII characters to ASCII. - Log responses to HTTP requests - Use the same log prefix for all of these log messages ("[LOGHTTP]"), to make them easy to see at a glance - Increased the snippet length to 200 (80 doesn't show enough), and add "..." only if the message was actually truncated Resolves http://opensimulator.org/mantis/view.php?id=6949
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs52
1 files changed, 38 insertions, 14 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index e243002..19231e1 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -46,6 +46,7 @@ using CoolHTTPListener = HttpServer.HttpListener;
46using HttpListener=System.Net.HttpListener; 46using HttpListener=System.Net.HttpListener;
47using LogPrio=HttpServer.LogPrio; 47using LogPrio=HttpServer.LogPrio;
48using OpenSim.Framework.Monitoring; 48using OpenSim.Framework.Monitoring;
49using System.IO.Compression;
49 50
50namespace OpenSim.Framework.Servers.HttpServer 51namespace OpenSim.Framework.Servers.HttpServer
51{ 52{
@@ -690,6 +691,23 @@ namespace OpenSim.Framework.Servers.HttpServer
690 691
691 if (buffer != null) 692 if (buffer != null)
692 { 693 {
694 if (WebUtil.DebugLevel >= 5)
695 {
696 string output = System.Text.Encoding.UTF8.GetString(buffer);
697
698 if (WebUtil.DebugLevel >= 6)
699 {
700 // Always truncate binary blobs. We don't have a ContentType, so detect them using the request name.
701 if ((requestHandler != null && requestHandler.Name == "GetMesh"))
702 {
703 if (output.Length > WebUtil.MaxRequestDiagLength)
704 output = output.Substring(0, WebUtil.MaxRequestDiagLength) + "...";
705 }
706 }
707
708 WebUtil.LogResponseDetail(output);
709 }
710
693 if (!response.SendChunked && response.ContentLength64 <= 0) 711 if (!response.SendChunked && response.ContentLength64 <= 0)
694 response.ContentLength64 = buffer.LongLength; 712 response.ContentLength64 = buffer.LongLength;
695 713
@@ -743,7 +761,7 @@ namespace OpenSim.Framework.Servers.HttpServer
743 if (tickdiff > 3000 && requestHandler != null && requestHandler.Name != "GetTexture") 761 if (tickdiff > 3000 && requestHandler != null && requestHandler.Name != "GetTexture")
744 { 762 {
745 m_log.InfoFormat( 763 m_log.InfoFormat(
746 "[BASE HTTP SERVER]: Slow handling of {0} {1} {2} {3} {4} from {5} took {6}ms", 764 "[LOGHTTP] Slow handling of {0} {1} {2} {3} {4} from {5} took {6}ms",
747 RequestNumber, 765 RequestNumber,
748 requestMethod, 766 requestMethod,
749 uriString, 767 uriString,
@@ -755,7 +773,7 @@ namespace OpenSim.Framework.Servers.HttpServer
755 else if (DebugLevel >= 4) 773 else if (DebugLevel >= 4)
756 { 774 {
757 m_log.DebugFormat( 775 m_log.DebugFormat(
758 "[BASE HTTP SERVER]: HTTP IN {0} :{1} took {2}ms", 776 "[LOGHTTP] HTTP IN {0} :{1} took {2}ms",
759 RequestNumber, 777 RequestNumber,
760 Port, 778 Port,
761 tickdiff); 779 tickdiff);
@@ -766,7 +784,7 @@ namespace OpenSim.Framework.Servers.HttpServer
766 private void LogIncomingToStreamHandler(OSHttpRequest request, IRequestHandler requestHandler) 784 private void LogIncomingToStreamHandler(OSHttpRequest request, IRequestHandler requestHandler)
767 { 785 {
768 m_log.DebugFormat( 786 m_log.DebugFormat(
769 "[BASE HTTP SERVER]: HTTP IN {0} :{1} stream handler {2} {3} {4} {5} from {6}", 787 "[LOGHTTP] HTTP IN {0} :{1} stream handler {2} {3} {4} {5} from {6}",
770 RequestNumber, 788 RequestNumber,
771 Port, 789 Port,
772 request.HttpMethod, 790 request.HttpMethod,
@@ -782,7 +800,7 @@ namespace OpenSim.Framework.Servers.HttpServer
782 private void LogIncomingToContentTypeHandler(OSHttpRequest request) 800 private void LogIncomingToContentTypeHandler(OSHttpRequest request)
783 { 801 {
784 m_log.DebugFormat( 802 m_log.DebugFormat(
785 "[BASE HTTP SERVER]: HTTP IN {0} :{1} {2} content type handler {3} {4} from {5}", 803 "[LOGHTTP] HTTP IN {0} :{1} {2} content type handler {3} {4} from {5}",
786 RequestNumber, 804 RequestNumber,
787 Port, 805 Port,
788 string.IsNullOrEmpty(request.ContentType) ? "not set" : request.ContentType, 806 string.IsNullOrEmpty(request.ContentType) ? "not set" : request.ContentType,
@@ -797,7 +815,7 @@ namespace OpenSim.Framework.Servers.HttpServer
797 private void LogIncomingToXmlRpcHandler(OSHttpRequest request) 815 private void LogIncomingToXmlRpcHandler(OSHttpRequest request)
798 { 816 {
799 m_log.DebugFormat( 817 m_log.DebugFormat(
800 "[BASE HTTP SERVER]: HTTP IN {0} :{1} assumed generic XMLRPC request {2} {3} from {4}", 818 "[LOGHTTP] HTTP IN {0} :{1} assumed generic XMLRPC request {2} {3} from {4}",
801 RequestNumber, 819 RequestNumber,
802 Port, 820 Port,
803 request.HttpMethod, 821 request.HttpMethod,
@@ -810,26 +828,32 @@ namespace OpenSim.Framework.Servers.HttpServer
810 828
811 private void LogIncomingInDetail(OSHttpRequest request) 829 private void LogIncomingInDetail(OSHttpRequest request)
812 { 830 {
813 using (StreamReader reader = new StreamReader(Util.Copy(request.InputStream), Encoding.UTF8)) 831 if (request.ContentType == "application/octet-stream")
832 return; // never log these; they're just binary data
833
834 Stream inputStream = Util.Copy(request.InputStream);
835
836 if (request.ContentType == "application/x-gzip")
837 inputStream = new GZipStream(inputStream, System.IO.Compression.CompressionMode.Decompress);
838
839 using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8))
814 { 840 {
815 string output; 841 string output;
816 842
817 if (DebugLevel == 5) 843 if (DebugLevel == 5)
818 { 844 {
819 const int sampleLength = 80; 845 char[] chars = new char[WebUtil.MaxRequestDiagLength + 1]; // +1 so we know to add "..." only if needed
820 char[] sampleChars = new char[sampleLength + 3]; 846 int len = reader.Read(chars, 0, WebUtil.MaxRequestDiagLength + 1);
821 reader.Read(sampleChars, 0, sampleLength); 847 output = new string(chars, 0, Math.Min(len, WebUtil.MaxRequestDiagLength));
822 sampleChars[80] = '.'; 848 if (len > WebUtil.MaxRequestDiagLength)
823 sampleChars[81] = '.'; 849 output += "...";
824 sampleChars[82] = '.';
825 output = new string(sampleChars);
826 } 850 }
827 else 851 else
828 { 852 {
829 output = reader.ReadToEnd(); 853 output = reader.ReadToEnd();
830 } 854 }
831 855
832 m_log.DebugFormat("[BASE HTTP SERVER]: {0}", output.Replace("\n", @"\n")); 856 m_log.DebugFormat("[LOGHTTP] {0}", Util.BinaryToASCII(output));
833 } 857 }
834 } 858 }
835 859