diff options
author | Justin Clarke Casey | 2008-03-31 17:34:32 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-03-31 17:34:32 +0000 |
commit | 48fc4ee059bea6c655686ee3ba7d2ff81b37dc4f (patch) | |
tree | dd91b7e00eae88b44246ec4719bb57336c87b5a2 /OpenSim/Framework/Servers/BaseHttpServer.cs | |
parent | * Fix problem where inventory code throws a swallowed exception on grid mode ... (diff) | |
download | opensim-SC-48fc4ee059bea6c655686ee3ba7d2ff81b37dc4f.zip opensim-SC-48fc4ee059bea6c655686ee3ba7d2ff81b37dc4f.tar.gz opensim-SC-48fc4ee059bea6c655686ee3ba7d2ff81b37dc4f.tar.bz2 opensim-SC-48fc4ee059bea6c655686ee3ba7d2ff81b37dc4f.tar.xz |
* Log exceptions which make it up to the top of the http request frame, rather than having them disappear off into the ether
Diffstat (limited to 'OpenSim/Framework/Servers/BaseHttpServer.cs')
-rw-r--r-- | OpenSim/Framework/Servers/BaseHttpServer.cs | 122 |
1 files changed, 67 insertions, 55 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index 0f6d79b..289b122 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs | |||
@@ -123,73 +123,85 @@ namespace OpenSim.Framework.Servers | |||
123 | return true; | 123 | return true; |
124 | } | 124 | } |
125 | 125 | ||
126 | /// <summary> | ||
127 | /// Handle an individual http request. This method is given to a worker in the thread pool. | ||
128 | /// </summary> | ||
129 | /// <param name="stateinfo"></param> | ||
126 | public virtual void HandleRequest(Object stateinfo) | 130 | public virtual void HandleRequest(Object stateinfo) |
127 | { | 131 | { |
128 | HttpListenerContext context = (HttpListenerContext) stateinfo; | 132 | // If we don't catch the exception here it will just disappear into the thread pool and we'll be none the wiser |
129 | 133 | try | |
130 | HttpListenerRequest request = context.Request; | ||
131 | HttpListenerResponse response = context.Response; | ||
132 | |||
133 | response.KeepAlive = false; | ||
134 | response.SendChunked = false; | ||
135 | |||
136 | string path = request.RawUrl; | ||
137 | string handlerKey = GetHandlerKey(request.HttpMethod, path); | ||
138 | |||
139 | IRequestHandler requestHandler; | ||
140 | |||
141 | if (TryGetStreamHandler(handlerKey, out requestHandler)) | ||
142 | { | 134 | { |
143 | // Okay, so this is bad, but should be considered temporary until everything is IStreamHandler. | 135 | HttpListenerContext context = (HttpListenerContext) stateinfo; |
144 | byte[] buffer; | 136 | |
145 | if (requestHandler is IStreamedRequestHandler) | 137 | HttpListenerRequest request = context.Request; |
138 | HttpListenerResponse response = context.Response; | ||
139 | |||
140 | response.KeepAlive = false; | ||
141 | response.SendChunked = false; | ||
142 | |||
143 | string path = request.RawUrl; | ||
144 | string handlerKey = GetHandlerKey(request.HttpMethod, path); | ||
145 | |||
146 | IRequestHandler requestHandler; | ||
147 | |||
148 | if (TryGetStreamHandler(handlerKey, out requestHandler)) | ||
146 | { | 149 | { |
147 | IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler; | 150 | // Okay, so this is bad, but should be considered temporary until everything is IStreamHandler. |
148 | buffer = streamedRequestHandler.Handle(path, request.InputStream); | 151 | byte[] buffer; |
152 | if (requestHandler is IStreamedRequestHandler) | ||
153 | { | ||
154 | IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler; | ||
155 | buffer = streamedRequestHandler.Handle(path, request.InputStream); | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | IStreamHandler streamHandler = (IStreamHandler) requestHandler; | ||
160 | |||
161 | using (MemoryStream memoryStream = new MemoryStream()) | ||
162 | { | ||
163 | streamHandler.Handle(path, request.InputStream, memoryStream); | ||
164 | memoryStream.Flush(); | ||
165 | buffer = memoryStream.ToArray(); | ||
166 | } | ||
167 | } | ||
168 | |||
169 | request.InputStream.Close(); | ||
170 | response.ContentType = requestHandler.ContentType; | ||
171 | response.ContentLength64 = buffer.LongLength; | ||
172 | |||
173 | try | ||
174 | { | ||
175 | response.OutputStream.Write(buffer, 0, buffer.Length); | ||
176 | response.OutputStream.Close(); | ||
177 | } | ||
178 | catch (HttpListenerException) | ||
179 | { | ||
180 | m_log.InfoFormat("[BASE HTTP SERVER] Http request abnormally terminated."); | ||
181 | } | ||
149 | } | 182 | } |
150 | else | 183 | else |
151 | { | 184 | { |
152 | IStreamHandler streamHandler = (IStreamHandler) requestHandler; | 185 | switch (request.ContentType) |
153 | |||
154 | using (MemoryStream memoryStream = new MemoryStream()) | ||
155 | { | 186 | { |
156 | streamHandler.Handle(path, request.InputStream, memoryStream); | 187 | case null: |
157 | memoryStream.Flush(); | 188 | case "text/html": |
158 | buffer = memoryStream.ToArray(); | 189 | HandleHTTPRequest(request, response); |
190 | break; | ||
191 | case "application/xml+llsd": | ||
192 | HandleLLSDRequests(request, response); | ||
193 | break; | ||
194 | case "text/xml": | ||
195 | case "application/xml": | ||
196 | default: | ||
197 | HandleXmlRpcRequests(request, response); | ||
198 | break; | ||
159 | } | 199 | } |
160 | } | 200 | } |
161 | |||
162 | request.InputStream.Close(); | ||
163 | response.ContentType = requestHandler.ContentType; | ||
164 | response.ContentLength64 = buffer.LongLength; | ||
165 | |||
166 | try | ||
167 | { | ||
168 | response.OutputStream.Write(buffer, 0, buffer.Length); | ||
169 | response.OutputStream.Close(); | ||
170 | } | ||
171 | catch (HttpListenerException) | ||
172 | { | ||
173 | m_log.InfoFormat("[BASEHTTPSERVER] Http request abnormally terminated."); | ||
174 | } | ||
175 | } | 201 | } |
176 | else | 202 | catch (Exception e) |
177 | { | 203 | { |
178 | switch (request.ContentType) | 204 | m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e); |
179 | { | ||
180 | case null: | ||
181 | case "text/html": | ||
182 | HandleHTTPRequest(request, response); | ||
183 | break; | ||
184 | case "application/xml+llsd": | ||
185 | HandleLLSDRequests(request, response); | ||
186 | break; | ||
187 | case "text/xml": | ||
188 | case "application/xml": | ||
189 | default: | ||
190 | HandleXmlRpcRequests(request, response); | ||
191 | break; | ||
192 | } | ||
193 | } | 205 | } |
194 | } | 206 | } |
195 | 207 | ||