aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Communications/RestClient.cs56
1 files changed, 30 insertions, 26 deletions
diff --git a/OpenSim/Framework/Communications/RestClient.cs b/OpenSim/Framework/Communications/RestClient.cs
index 4a8301e..6f517b6 100644
--- a/OpenSim/Framework/Communications/RestClient.cs
+++ b/OpenSim/Framework/Communications/RestClient.cs
@@ -352,42 +352,46 @@ namespace OpenSim.Framework.Communications
352 m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} REST {1} to {2}", reqnum, _request.Method, _request.RequestUri); 352 m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} REST {1} to {2}", reqnum, _request.Method, _request.RequestUri);
353 353
354// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); 354// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request);
355
355 try 356 try
356 { 357 {
357 _response = (HttpWebResponse) _request.GetResponse(); 358 using (_response = (HttpWebResponse) _request.GetResponse())
359 {
360 using (Stream src = _response.GetResponseStream())
361 {
362 int length = src.Read(_readbuf, 0, BufferSize);
363 while (length > 0)
364 {
365 _resource.Write(_readbuf, 0, length);
366 length = src.Read(_readbuf, 0, BufferSize);
367 }
368
369 // TODO! Implement timeout, without killing the server
370 // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted
371 //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true);
372
373 // _allDone.WaitOne();
374 }
375 }
358 } 376 }
359 catch (WebException e) 377 catch (WebException e)
360 { 378 {
361 HttpWebResponse errorResponse = e.Response as HttpWebResponse; 379 using (HttpWebResponse errorResponse = e.Response as HttpWebResponse)
362 if (null != errorResponse && HttpStatusCode.NotFound == errorResponse.StatusCode)
363 {
364 // This is often benign. E.g., requesting a missing asset will return 404.
365 m_log.DebugFormat("[REST CLIENT] Resource not found (404): {0}", _request.Address.ToString());
366 }
367 else
368 { 380 {
369 m_log.Error(string.Format("[REST CLIENT] Error fetching resource from server: {0} ", _request.Address.ToString()), e); 381 if (null != errorResponse && HttpStatusCode.NotFound == errorResponse.StatusCode)
382 {
383 // This is often benign. E.g., requesting a missing asset will return 404.
384 m_log.DebugFormat("[REST CLIENT] Resource not found (404): {0}", _request.Address.ToString());
385 }
386 else
387 {
388 m_log.Error(string.Format("[REST CLIENT] Error fetching resource from server: {0} ", _request.Address.ToString()), e);
389 }
370 } 390 }
371 391
372 return null; 392 return null;
373 } 393 }
374 394
375 Stream src = _response.GetResponseStream();
376 int length = src.Read(_readbuf, 0, BufferSize);
377 while (length > 0)
378 {
379 _resource.Write(_readbuf, 0, length);
380 length = src.Read(_readbuf, 0, BufferSize);
381 }
382
383
384 // TODO! Implement timeout, without killing the server
385 // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted
386 //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true);
387
388// _allDone.WaitOne();
389 if (_response != null)
390 _response.Close();
391 if (_asyncException != null) 395 if (_asyncException != null)
392 throw _asyncException; 396 throw _asyncException;
393 397
@@ -515,4 +519,4 @@ namespace OpenSim.Framework.Communications
515 519
516 #endregion Async Invocation 520 #endregion Async Invocation
517 } 521 }
518} 522} \ No newline at end of file