diff options
author | onefang | 2019-09-11 16:36:50 +1000 |
---|---|---|
committer | onefang | 2019-09-11 16:36:50 +1000 |
commit | 50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch) | |
tree | 52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Region/CoreModules/Scripting/HttpRequest | |
parent | Renamed branch to SledjChisl. (diff) | |
parent | Bump to release flavour, build 0. (diff) | |
download | opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2 opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz |
Merge branch 'SledjChisl'
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | 261 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/HttpRequest/Tests/ScriptsHttpRequestsTests.cs | 22 |
2 files changed, 169 insertions, 114 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index 9dfeb96..84b4707 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | |||
@@ -28,15 +28,12 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Linq; | ||
32 | using System.Net; | 31 | using System.Net; |
33 | using System.Net.Mail; | 32 | using System.Net.Mail; |
34 | using System.Net.Security; | 33 | using System.Net.Security; |
35 | using System.Reflection; | ||
36 | using System.Text; | 34 | using System.Text; |
37 | using System.Threading; | 35 | using System.Threading; |
38 | using System.Security.Cryptography.X509Certificates; | 36 | using System.Security.Cryptography.X509Certificates; |
39 | using log4net; | ||
40 | using Nini.Config; | 37 | using Nini.Config; |
41 | using OpenMetaverse; | 38 | using OpenMetaverse; |
42 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
@@ -45,6 +42,7 @@ using OpenSim.Framework.Servers.HttpServer; | |||
45 | using OpenSim.Region.Framework.Interfaces; | 42 | using OpenSim.Region.Framework.Interfaces; |
46 | using OpenSim.Region.Framework.Scenes; | 43 | using OpenSim.Region.Framework.Scenes; |
47 | using Mono.Addins; | 44 | using Mono.Addins; |
45 | using Amib.Threading; | ||
48 | 46 | ||
49 | /***************************************************** | 47 | /***************************************************** |
50 | * | 48 | * |
@@ -108,6 +106,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
108 | private Dictionary<UUID, HttpRequestClass> m_pendingRequests; | 106 | private Dictionary<UUID, HttpRequestClass> m_pendingRequests; |
109 | private Scene m_scene; | 107 | private Scene m_scene; |
110 | // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); | 108 | // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); |
109 | public static SmartThreadPool ThreadPool = null; | ||
111 | 110 | ||
112 | public HttpRequestModule() | 111 | public HttpRequestModule() |
113 | { | 112 | { |
@@ -191,7 +190,15 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
191 | 190 | ||
192 | case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: | 191 | case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: |
193 | 192 | ||
194 | // TODO implement me | 193 | int len; |
194 | if(int.TryParse(parms[i + 1], out len)) | ||
195 | { | ||
196 | if(len > HttpRequestClass.HttpBodyMaxLenMAX) | ||
197 | len = HttpRequestClass.HttpBodyMaxLenMAX; | ||
198 | else if(len < 64) //??? | ||
199 | len = 64; | ||
200 | htc.HttpBodyMaxLen = len; | ||
201 | } | ||
195 | break; | 202 | break; |
196 | 203 | ||
197 | case (int)HttpRequestConstants.HTTP_VERIFY_CERT: | 204 | case (int)HttpRequestConstants.HTTP_VERIFY_CERT: |
@@ -216,20 +223,16 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
216 | if (parms.Length - i < 2) | 223 | if (parms.Length - i < 2) |
217 | break; | 224 | break; |
218 | 225 | ||
219 | //Have we reached the end of the list of headers? | ||
220 | //End is marked by a string with a single digit. | ||
221 | //We already know we have at least one parameter | ||
222 | //so it is safe to do this check at top of loop. | ||
223 | if (Char.IsDigit(parms[i][0])) | ||
224 | break; | ||
225 | |||
226 | if (htc.HttpCustomHeaders == null) | 226 | if (htc.HttpCustomHeaders == null) |
227 | htc.HttpCustomHeaders = new List<string>(); | 227 | htc.HttpCustomHeaders = new List<string>(); |
228 | 228 | ||
229 | htc.HttpCustomHeaders.Add(parms[i]); | 229 | htc.HttpCustomHeaders.Add(parms[i]); |
230 | htc.HttpCustomHeaders.Add(parms[i+1]); | 230 | htc.HttpCustomHeaders.Add(parms[i+1]); |
231 | int nexti = i + 2; | ||
232 | if (nexti >= parms.Length || Char.IsDigit(parms[nexti][0])) | ||
233 | break; | ||
231 | 234 | ||
232 | i += 2; | 235 | i = nexti; |
233 | } | 236 | } |
234 | break; | 237 | break; |
235 | 238 | ||
@@ -239,7 +242,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
239 | } | 242 | } |
240 | } | 243 | } |
241 | } | 244 | } |
242 | 245 | ||
243 | htc.RequestModule = this; | 246 | htc.RequestModule = this; |
244 | htc.LocalID = localID; | 247 | htc.LocalID = localID; |
245 | htc.ItemID = itemID; | 248 | htc.ItemID = itemID; |
@@ -276,7 +279,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
276 | } | 279 | } |
277 | 280 | ||
278 | public bool StartHttpRequest(HttpRequestClass req) | 281 | public bool StartHttpRequest(HttpRequestClass req) |
279 | { | 282 | { |
280 | if (!CheckAllowed(new Uri(req.Url))) | 283 | if (!CheckAllowed(new Uri(req.Url))) |
281 | return false; | 284 | return false; |
282 | 285 | ||
@@ -290,29 +293,18 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
290 | return true; | 293 | return true; |
291 | } | 294 | } |
292 | 295 | ||
293 | public void StopHttpRequestsForScript(UUID id) | 296 | public void StopHttpRequest(uint m_localID, UUID m_itemID) |
294 | { | 297 | { |
295 | if (m_pendingRequests != null) | 298 | if (m_pendingRequests != null) |
296 | { | 299 | { |
297 | List<UUID> keysToRemove = null; | ||
298 | |||
299 | lock (HttpListLock) | 300 | lock (HttpListLock) |
300 | { | 301 | { |
301 | foreach (HttpRequestClass req in m_pendingRequests.Values) | 302 | HttpRequestClass tmpReq; |
303 | if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq)) | ||
302 | { | 304 | { |
303 | if (req.ItemID == id) | 305 | tmpReq.Stop(); |
304 | { | 306 | m_pendingRequests.Remove(m_itemID); |
305 | req.Stop(); | ||
306 | |||
307 | if (keysToRemove == null) | ||
308 | keysToRemove = new List<UUID>(); | ||
309 | |||
310 | keysToRemove.Add(req.ReqID); | ||
311 | } | ||
312 | } | 307 | } |
313 | |||
314 | if (keysToRemove != null) | ||
315 | keysToRemove.ForEach(keyToRemove => m_pendingRequests.Remove(keyToRemove)); | ||
316 | } | 308 | } |
317 | } | 309 | } |
318 | } | 310 | } |
@@ -330,13 +322,19 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
330 | { | 322 | { |
331 | lock (HttpListLock) | 323 | lock (HttpListLock) |
332 | { | 324 | { |
333 | foreach (HttpRequestClass req in m_pendingRequests.Values) | 325 | foreach (UUID luid in m_pendingRequests.Keys) |
334 | { | 326 | { |
335 | if (req.Finished) | 327 | HttpRequestClass tmpReq; |
336 | return req; | 328 | |
329 | if (m_pendingRequests.TryGetValue(luid, out tmpReq)) | ||
330 | { | ||
331 | if (tmpReq.Finished) | ||
332 | { | ||
333 | return tmpReq; | ||
334 | } | ||
335 | } | ||
337 | } | 336 | } |
338 | } | 337 | } |
339 | |||
340 | return null; | 338 | return null; |
341 | } | 339 | } |
342 | 340 | ||
@@ -363,9 +361,34 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
363 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); | 361 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); |
364 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); | 362 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); |
365 | 363 | ||
364 | HttpRequestClass.HttpBodyMaxLenMAX = config.Configs["Network"].GetInt("HttpBodyMaxLenMAX", 16384); | ||
365 | |||
366 | |||
366 | m_outboundUrlFilter = new OutboundUrlFilter("Script HTTP request module", config); | 367 | m_outboundUrlFilter = new OutboundUrlFilter("Script HTTP request module", config); |
368 | int maxThreads = 15; | ||
369 | |||
370 | IConfig httpConfig = config.Configs["HttpRequestModule"]; | ||
371 | if (httpConfig != null) | ||
372 | { | ||
373 | maxThreads = httpConfig.GetInt("MaxPoolThreads", maxThreads); | ||
374 | } | ||
367 | 375 | ||
368 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); | 376 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); |
377 | |||
378 | // First instance sets this up for all sims | ||
379 | if (ThreadPool == null) | ||
380 | { | ||
381 | STPStartInfo startInfo = new STPStartInfo(); | ||
382 | startInfo.IdleTimeout = 2000; | ||
383 | startInfo.MaxWorkerThreads = maxThreads; | ||
384 | startInfo.MinWorkerThreads = 0; | ||
385 | startInfo.ThreadPriority = ThreadPriority.BelowNormal; | ||
386 | startInfo.StartSuspended = true; | ||
387 | startInfo.ThreadPoolName = "ScriptsHttpReq"; | ||
388 | |||
389 | ThreadPool = new SmartThreadPool(startInfo); | ||
390 | ThreadPool.Start(); | ||
391 | } | ||
369 | } | 392 | } |
370 | 393 | ||
371 | public void AddRegion(Scene scene) | 394 | public void AddRegion(Scene scene) |
@@ -392,6 +415,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
392 | 415 | ||
393 | public void Close() | 416 | public void Close() |
394 | { | 417 | { |
418 | ThreadPool.Shutdown(); | ||
395 | } | 419 | } |
396 | 420 | ||
397 | public string Name | 421 | public string Name |
@@ -409,8 +433,6 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
409 | 433 | ||
410 | public class HttpRequestClass : IServiceRequest | 434 | public class HttpRequestClass : IServiceRequest |
411 | { | 435 | { |
412 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
413 | |||
414 | // Constants for parameters | 436 | // Constants for parameters |
415 | // public const int HTTP_BODY_MAXLENGTH = 2; | 437 | // public const int HTTP_BODY_MAXLENGTH = 2; |
416 | // public const int HTTP_METHOD = 0; | 438 | // public const int HTTP_METHOD = 0; |
@@ -430,13 +452,17 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
430 | { | 452 | { |
431 | get { return _finished; } | 453 | get { return _finished; } |
432 | } | 454 | } |
433 | // public int HttpBodyMaxLen = 2048; // not implemented | 455 | |
456 | public static int HttpBodyMaxLenMAX = 16384; | ||
434 | 457 | ||
435 | // Parameter members and default values | 458 | // Parameter members and default values |
459 | public int HttpBodyMaxLen = 2048; | ||
436 | public string HttpMethod = "GET"; | 460 | public string HttpMethod = "GET"; |
437 | public string HttpMIMEType = "text/plain;charset=utf-8"; | 461 | public string HttpMIMEType = "text/plain;charset=utf-8"; |
438 | public int HttpTimeout; | 462 | public int HttpTimeout; |
439 | public bool HttpVerifyCert = true; | 463 | public bool HttpVerifyCert = true; |
464 | public IWorkItemResult WorkItem = null; | ||
465 | |||
440 | //public bool HttpVerboseThrottle = true; // not implemented | 466 | //public bool HttpVerboseThrottle = true; // not implemented |
441 | public List<string> HttpCustomHeaders = null; | 467 | public List<string> HttpCustomHeaders = null; |
442 | public bool HttpPragmaNoCache = true; | 468 | public bool HttpPragmaNoCache = true; |
@@ -484,15 +510,40 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
484 | 510 | ||
485 | public void Process() | 511 | public void Process() |
486 | { | 512 | { |
513 | _finished = false; | ||
514 | |||
515 | lock (HttpRequestModule.ThreadPool) | ||
516 | WorkItem = HttpRequestModule.ThreadPool.QueueWorkItem(new WorkItemCallback(StpSendWrapper), null); | ||
517 | } | ||
518 | |||
519 | private object StpSendWrapper(object o) | ||
520 | { | ||
487 | SendRequest(); | 521 | SendRequest(); |
522 | return null; | ||
488 | } | 523 | } |
489 | 524 | ||
525 | /* | ||
526 | * TODO: More work on the response codes. Right now | ||
527 | * returning 200 for success or 499 for exception | ||
528 | */ | ||
529 | |||
490 | public void SendRequest() | 530 | public void SendRequest() |
491 | { | 531 | { |
532 | HttpWebResponse response = null; | ||
533 | Stream resStream = null; | ||
534 | byte[] buf = new byte[HttpBodyMaxLenMAX + 16]; | ||
535 | string tempString = null; | ||
536 | int count = 0; | ||
537 | |||
492 | try | 538 | try |
493 | { | 539 | { |
494 | Request = (HttpWebRequest)WebRequest.Create(Url); | 540 | Request = (HttpWebRequest)WebRequest.Create(Url); |
495 | Request.AllowAutoRedirect = false; | 541 | Request.AllowAutoRedirect = false; |
542 | Request.KeepAlive = false; | ||
543 | |||
544 | //This works around some buggy HTTP Servers like Lighttpd | ||
545 | Request.ServicePoint.Expect100Continue = false; | ||
546 | |||
496 | Request.Method = HttpMethod; | 547 | Request.Method = HttpMethod; |
497 | Request.ContentType = HttpMIMEType; | 548 | Request.ContentType = HttpMIMEType; |
498 | 549 | ||
@@ -500,7 +551,6 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
500 | { | 551 | { |
501 | // We could hijack Connection Group Name to identify | 552 | // We could hijack Connection Group Name to identify |
502 | // a desired security exception. But at the moment we'll use a dummy header instead. | 553 | // a desired security exception. But at the moment we'll use a dummy header instead. |
503 | // Request.ConnectionGroupName = "NoVerify"; | ||
504 | Request.Headers.Add("NoVerifyCert", "true"); | 554 | Request.Headers.Add("NoVerifyCert", "true"); |
505 | } | 555 | } |
506 | // else | 556 | // else |
@@ -533,14 +583,11 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
533 | } | 583 | } |
534 | } | 584 | } |
535 | 585 | ||
536 | if (ResponseHeaders != null) | 586 | foreach (KeyValuePair<string, string> entry in ResponseHeaders) |
537 | { | 587 | if (entry.Key.ToLower().Equals("user-agent")) |
538 | foreach (KeyValuePair<string, string> entry in ResponseHeaders) | 588 | Request.UserAgent = entry.Value; |
539 | if (entry.Key.ToLower().Equals("user-agent") && Request is HttpWebRequest) | 589 | else |
540 | ((HttpWebRequest)Request).UserAgent = entry.Value; | 590 | Request.Headers[entry.Key] = entry.Value; |
541 | else | ||
542 | Request.Headers[entry.Key] = entry.Value; | ||
543 | } | ||
544 | 591 | ||
545 | // Encode outbound data | 592 | // Encode outbound data |
546 | if (!string.IsNullOrEmpty(OutboundBody)) | 593 | if (!string.IsNullOrEmpty(OutboundBody)) |
@@ -552,12 +599,11 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
552 | bstream.Write(data, 0, data.Length); | 599 | bstream.Write(data, 0, data.Length); |
553 | } | 600 | } |
554 | 601 | ||
602 | Request.Timeout = HttpTimeout; | ||
555 | try | 603 | try |
556 | { | 604 | { |
557 | IAsyncResult result = (IAsyncResult)Request.BeginGetResponse(ResponseCallback, null); | 605 | // execute the request |
558 | 606 | response = (HttpWebResponse) Request.GetResponse(); | |
559 | ThreadPool.RegisterWaitForSingleObject( | ||
560 | result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), null, HttpTimeout, true); | ||
561 | } | 607 | } |
562 | catch (WebException e) | 608 | catch (WebException e) |
563 | { | 609 | { |
@@ -565,67 +611,74 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
565 | { | 611 | { |
566 | throw; | 612 | throw; |
567 | } | 613 | } |
614 | response = (HttpWebResponse)e.Response; | ||
615 | } | ||
568 | 616 | ||
569 | HttpWebResponse response = (HttpWebResponse)e.Response; | 617 | Status = (int)response.StatusCode; |
570 | 618 | ||
571 | Status = (int)response.StatusCode; | 619 | resStream = response.GetResponseStream(); |
572 | ResponseBody = response.StatusDescription; | 620 | int totalBodyBytes = 0; |
573 | _finished = true; | 621 | int maxBytes = HttpBodyMaxLen; |
574 | } | 622 | if(maxBytes > buf.Length) |
575 | } | 623 | maxBytes = buf.Length; |
576 | catch (Exception e) | ||
577 | { | ||
578 | // m_log.Debug( | ||
579 | // string.Format("[SCRIPTS HTTP REQUESTS]: Exception on request to {0} for {1} ", Url, ItemID), e); | ||
580 | 624 | ||
581 | Status = (int)OSHttpStatusCode.ClientErrorJoker; | 625 | // we need to read all allowed or UFT8 conversion may fail |
582 | ResponseBody = e.Message; | 626 | do |
583 | _finished = true; | 627 | { |
584 | } | 628 | // fill the buffer with data |
585 | } | 629 | count = resStream.Read(buf, totalBodyBytes, maxBytes - totalBodyBytes); |
630 | totalBodyBytes += count; | ||
631 | if (totalBodyBytes >= maxBytes) | ||
632 | break; | ||
586 | 633 | ||
587 | private void ResponseCallback(IAsyncResult ar) | 634 | } while (count > 0); // any more data to read? |
588 | { | ||
589 | HttpWebResponse response = null; | ||
590 | 635 | ||
591 | try | 636 | if(totalBodyBytes > 0) |
592 | { | ||
593 | try | ||
594 | { | 637 | { |
595 | response = (HttpWebResponse)Request.EndGetResponse(ar); | 638 | tempString = Util.UTF8.GetString(buf, 0, totalBodyBytes); |
639 | ResponseBody = tempString.Replace("\r", ""); | ||
596 | } | 640 | } |
597 | catch (WebException e) | 641 | else |
642 | ResponseBody = ""; | ||
643 | } | ||
644 | catch (WebException e) | ||
645 | { | ||
646 | if (e.Status == WebExceptionStatus.ProtocolError) | ||
598 | { | 647 | { |
599 | if (e.Status != WebExceptionStatus.ProtocolError) | 648 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; |
649 | Status = (int)webRsp.StatusCode; | ||
650 | try | ||
600 | { | 651 | { |
601 | throw; | 652 | using (Stream responseStream = webRsp.GetResponseStream()) |
653 | { | ||
654 | using (StreamReader reader = new StreamReader(responseStream)) | ||
655 | ResponseBody = reader.ReadToEnd(); | ||
656 | } | ||
657 | } | ||
658 | catch | ||
659 | { | ||
660 | ResponseBody = webRsp.StatusDescription; | ||
602 | } | 661 | } |
603 | |||
604 | response = (HttpWebResponse)e.Response; | ||
605 | } | 662 | } |
606 | 663 | else | |
607 | Status = (int)response.StatusCode; | ||
608 | |||
609 | using (Stream stream = response.GetResponseStream()) | ||
610 | { | 664 | { |
611 | StreamReader reader = new StreamReader(stream, Encoding.UTF8); | 665 | Status = (int)OSHttpStatusCode.ClientErrorJoker; |
612 | ResponseBody = reader.ReadToEnd(); | 666 | ResponseBody = e.Message; |
613 | } | 667 | } |
614 | } | 668 | } |
615 | catch (Exception e) | 669 | catch (Exception) |
616 | { | 670 | { |
617 | Status = (int)OSHttpStatusCode.ClientErrorJoker; | 671 | // Don't crash on anything else |
618 | ResponseBody = e.Message; | ||
619 | |||
620 | // m_log.Debug( | ||
621 | // string.Format("[SCRIPTS HTTP REQUESTS]: Exception on response to {0} for {1} ", Url, ItemID), e); | ||
622 | } | 672 | } |
623 | finally | 673 | finally |
624 | { | 674 | { |
675 | if (resStream != null) | ||
676 | resStream.Close(); | ||
625 | if (response != null) | 677 | if (response != null) |
626 | response.Close(); | 678 | response.Close(); |
627 | 679 | ||
628 | // We need to resubmit | 680 | |
681 | // We need to resubmit | ||
629 | if ( | 682 | if ( |
630 | (Status == (int)HttpStatusCode.MovedPermanently | 683 | (Status == (int)HttpStatusCode.MovedPermanently |
631 | || Status == (int)HttpStatusCode.Found | 684 | || Status == (int)HttpStatusCode.Found |
@@ -670,22 +723,24 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
670 | else | 723 | else |
671 | { | 724 | { |
672 | _finished = true; | 725 | _finished = true; |
726 | if (ResponseBody == null) | ||
727 | ResponseBody = String.Empty; | ||
673 | } | 728 | } |
674 | } | 729 | } |
675 | } | 730 | } |
676 | 731 | ||
677 | private void TimeoutCallback(object state, bool timedOut) | ||
678 | { | ||
679 | if (timedOut) | ||
680 | Request.Abort(); | ||
681 | } | ||
682 | |||
683 | public void Stop() | 732 | public void Stop() |
684 | { | 733 | { |
685 | // m_log.DebugFormat("[SCRIPTS HTTP REQUESTS]: Stopping request to {0} for {1} ", Url, ItemID); | 734 | try |
686 | 735 | { | |
687 | if (Request != null) | 736 | if (!WorkItem.Cancel()) |
688 | Request.Abort(); | 737 | { |
738 | WorkItem.Cancel(true); | ||
739 | } | ||
740 | } | ||
741 | catch (Exception) | ||
742 | { | ||
743 | } | ||
689 | } | 744 | } |
690 | } | 745 | } |
691 | } \ No newline at end of file | 746 | } |
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/Tests/ScriptsHttpRequestsTests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/Tests/ScriptsHttpRequestsTests.cs index d22487e..7e223d7 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/Tests/ScriptsHttpRequestsTests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/Tests/ScriptsHttpRequestsTests.cs | |||
@@ -45,7 +45,7 @@ using OpenSim.Tests.Common; | |||
45 | namespace OpenSim.Region.CoreModules.Scripting.HttpRequest.Tests | 45 | namespace OpenSim.Region.CoreModules.Scripting.HttpRequest.Tests |
46 | { | 46 | { |
47 | class TestWebRequestCreate : IWebRequestCreate | 47 | class TestWebRequestCreate : IWebRequestCreate |
48 | { | 48 | { |
49 | public TestWebRequest NextRequest { get; set; } | 49 | public TestWebRequest NextRequest { get; set; } |
50 | 50 | ||
51 | public WebRequest Create(Uri uri) | 51 | public WebRequest Create(Uri uri) |
@@ -65,13 +65,13 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest.Tests | |||
65 | 65 | ||
66 | public Func<IAsyncResult, WebResponse> OnEndGetResponse { get; set; } | 66 | public Func<IAsyncResult, WebResponse> OnEndGetResponse { get; set; } |
67 | 67 | ||
68 | public TestWebRequest() : base() | 68 | public TestWebRequest() : base() |
69 | { | 69 | { |
70 | // Console.WriteLine("created"); | 70 | // Console.WriteLine("created"); |
71 | } | 71 | } |
72 | 72 | ||
73 | // public TestWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext) | 73 | // public TestWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext) |
74 | // : base(serializationInfo, streamingContext) | 74 | // : base(serializationInfo, streamingContext) |
75 | // { | 75 | // { |
76 | // Console.WriteLine("created"); | 76 | // Console.WriteLine("created"); |
77 | // } | 77 | // } |
@@ -97,7 +97,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest.Tests | |||
97 | public string Response { get; set; } | 97 | public string Response { get; set; } |
98 | 98 | ||
99 | #pragma warning disable 0618 | 99 | #pragma warning disable 0618 |
100 | public TestHttpWebResponse(SerializationInfo serializationInfo, StreamingContext streamingContext) | 100 | public TestHttpWebResponse(SerializationInfo serializationInfo, StreamingContext streamingContext) |
101 | : base(serializationInfo, streamingContext) {} | 101 | : base(serializationInfo, streamingContext) {} |
102 | #pragma warning restore 0618 | 102 | #pragma warning restore 0618 |
103 | 103 | ||
@@ -111,24 +111,24 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest.Tests | |||
111 | { | 111 | { |
112 | WaitHandle m_wh = new ManualResetEvent(true); | 112 | WaitHandle m_wh = new ManualResetEvent(true); |
113 | 113 | ||
114 | object IAsyncResult.AsyncState | 114 | object IAsyncResult.AsyncState |
115 | { | 115 | { |
116 | get { | 116 | get { |
117 | throw new System.NotImplementedException (); | 117 | throw new System.NotImplementedException (); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | WaitHandle IAsyncResult.AsyncWaitHandle | 121 | WaitHandle IAsyncResult.AsyncWaitHandle |
122 | { | 122 | { |
123 | get { return m_wh; } | 123 | get { return m_wh; } |
124 | } | 124 | } |
125 | 125 | ||
126 | bool IAsyncResult.CompletedSynchronously | 126 | bool IAsyncResult.CompletedSynchronously |
127 | { | 127 | { |
128 | get { return false; } | 128 | get { return false; } |
129 | } | 129 | } |
130 | 130 | ||
131 | bool IAsyncResult.IsCompleted | 131 | bool IAsyncResult.IsCompleted |
132 | { | 132 | { |
133 | get { return true; } | 133 | get { return true; } |
134 | } | 134 | } |
@@ -155,7 +155,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest.Tests | |||
155 | TestHelpers.EnableLogging(); | 155 | TestHelpers.EnableLogging(); |
156 | 156 | ||
157 | if (!Util.IsPlatformMono) | 157 | if (!Util.IsPlatformMono) |
158 | Assert.Ignore("Ignoring test since can only currently run on Mono"); | 158 | Assert.Ignore("Ignoring test since can only currently run on Mono"); |
159 | 159 | ||
160 | string rawResponse = "boom"; | 160 | string rawResponse = "boom"; |
161 | 161 | ||
@@ -163,7 +163,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest.Tests | |||
163 | 163 | ||
164 | TestWebRequest twr = new TestWebRequest(); | 164 | TestWebRequest twr = new TestWebRequest(); |
165 | //twr.OnEndGetResponse += ar => new TestHttpWebResponse(null, new StreamingContext()); | 165 | //twr.OnEndGetResponse += ar => new TestHttpWebResponse(null, new StreamingContext()); |
166 | twr.OnEndGetResponse += ar => | 166 | twr.OnEndGetResponse += ar => |
167 | { | 167 | { |
168 | SerializationInfo si = new SerializationInfo(typeof(HttpWebResponse), new FormatterConverter()); | 168 | SerializationInfo si = new SerializationInfo(typeof(HttpWebResponse), new FormatterConverter()); |
169 | StreamingContext sc = new StreamingContext(); | 169 | StreamingContext sc = new StreamingContext(); |