ScriptsHttpRequests.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Net;
  31. using System.Net.Mail;
  32. using System.Net.Security;
  33. using System.Text;
  34. using System.Threading;
  35. using System.Security.Cryptography.X509Certificates;
  36. using Nini.Config;
  37. using OpenMetaverse;
  38. using OpenSim.Framework;
  39. using OpenSim.Framework.Servers;
  40. using OpenSim.Framework.Servers.HttpServer;
  41. using OpenSim.Region.Framework.Interfaces;
  42. using OpenSim.Region.Framework.Scenes;
  43. using Mono.Addins;
  44. using Amib.Threading;
  45. /*****************************************************
  46. *
  47. * ScriptsHttpRequests
  48. *
  49. * Implements the llHttpRequest and http_response
  50. * callback.
  51. *
  52. * Some stuff was already in LSLLongCmdHandler, and then
  53. * there was this file with a stub class in it. So,
  54. * I am moving some of the objects and functions out of
  55. * LSLLongCmdHandler, such as the HttpRequestClass, the
  56. * start and stop methods, and setting up pending and
  57. * completed queues. These are processed in the
  58. * LSLLongCmdHandler polling loop. Similiar to the
  59. * XMLRPCModule, since that seems to work.
  60. *
  61. * //TODO
  62. *
  63. * This probably needs some throttling mechanism but
  64. * it's wide open right now. This applies to both
  65. * number of requests and data volume.
  66. *
  67. * Linden puts all kinds of header fields in the requests.
  68. * Not doing any of that:
  69. * User-Agent
  70. * X-SecondLife-Shard
  71. * X-SecondLife-Object-Name
  72. * X-SecondLife-Object-Key
  73. * X-SecondLife-Region
  74. * X-SecondLife-Local-Position
  75. * X-SecondLife-Local-Velocity
  76. * X-SecondLife-Local-Rotation
  77. * X-SecondLife-Owner-Name
  78. * X-SecondLife-Owner-Key
  79. *
  80. * HTTPS support
  81. *
  82. * Configurable timeout?
  83. * Configurable max response size?
  84. * Configurable
  85. *
  86. * **************************************************/
  87. namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
  88. {
  89. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HttpRequestModule")]
  90. public class HttpRequestModule : ISharedRegionModule, IHttpRequestModule
  91. {
  92. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  93. private object HttpListLock = new object();
  94. private int httpTimeout = 30000;
  95. private string m_name = "HttpScriptRequests";
  96. private OutboundUrlFilter m_outboundUrlFilter;
  97. private string m_proxyurl = "";
  98. private string m_proxyexcepts = "";
  99. // <request id, HttpRequestClass>
  100. private Dictionary<UUID, HttpRequestClass> m_pendingRequests;
  101. private Scene m_scene;
  102. // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>();
  103. public static SmartThreadPool ThreadPool = null;
  104. public HttpRequestModule()
  105. {
  106. ServicePointManager.ServerCertificateValidationCallback +=ValidateServerCertificate;
  107. }
  108. public static bool ValidateServerCertificate(
  109. object sender,
  110. X509Certificate certificate,
  111. X509Chain chain,
  112. SslPolicyErrors sslPolicyErrors)
  113. {
  114. // If this is a web request we need to check the headers first
  115. // We may want to ignore SSL
  116. if (sender is HttpWebRequest)
  117. {
  118. HttpWebRequest Request = (HttpWebRequest)sender;
  119. ServicePoint sp = Request.ServicePoint;
  120. // We don't case about encryption, get out of here
  121. if (Request.Headers.Get("NoVerifyCert") != null)
  122. {
  123. return true;
  124. }
  125. // If there was an upstream cert verification error, bail
  126. if ((((int)sslPolicyErrors) & ~4) != 0)
  127. return false;
  128. // Check for policy and execute it if defined
  129. #pragma warning disable 0618
  130. if (ServicePointManager.CertificatePolicy != null)
  131. {
  132. return ServicePointManager.CertificatePolicy.CheckValidationResult (sp, certificate, Request, 0);
  133. }
  134. #pragma warning restore 0618
  135. return true;
  136. }
  137. // If it's not HTTP, trust .NET to check it
  138. if ((((int)sslPolicyErrors) & ~4) != 0)
  139. return false;
  140. return true;
  141. }
  142. #region IHttpRequestModule Members
  143. public UUID MakeHttpRequest(string url, string parameters, string body)
  144. {
  145. return UUID.Zero;
  146. }
  147. public UUID StartHttpRequest(
  148. uint localID, UUID itemID, string url, List<string> parameters, Dictionary<string, string> headers, string body,
  149. out HttpInitialRequestStatus status)
  150. {
  151. UUID reqID = UUID.Random();
  152. HttpRequestClass htc = new HttpRequestClass();
  153. // Partial implementation: support for parameter flags needed
  154. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  155. //
  156. // Parameters are expected in {key, value, ... , key, value}
  157. if (parameters != null)
  158. {
  159. string[] parms = parameters.ToArray();
  160. for (int i = 0; i < parms.Length; i += 2)
  161. {
  162. switch (Int32.Parse(parms[i]))
  163. {
  164. case (int)HttpRequestConstants.HTTP_METHOD:
  165. htc.HttpMethod = parms[i + 1];
  166. break;
  167. case (int)HttpRequestConstants.HTTP_MIMETYPE:
  168. htc.HttpMIMEType = parms[i + 1];
  169. break;
  170. case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH:
  171. // TODO implement me
  172. break;
  173. case (int)HttpRequestConstants.HTTP_VERIFY_CERT:
  174. htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0);
  175. break;
  176. case (int)HttpRequestConstants.HTTP_VERBOSE_THROTTLE:
  177. // TODO implement me
  178. break;
  179. case (int)HttpRequestConstants.HTTP_CUSTOM_HEADER:
  180. //Parameters are in pairs and custom header takes
  181. //arguments in pairs so adjust for header marker.
  182. ++i;
  183. //Maximum of 8 headers are allowed based on the
  184. //Second Life documentation for llHTTPRequest.
  185. for (int count = 1; count <= 8; ++count)
  186. {
  187. //Not enough parameters remaining for a header?
  188. if (parms.Length - i < 2)
  189. break;
  190. //Have we reached the end of the list of headers?
  191. //End is marked by a string with a single digit.
  192. //We already know we have at least one parameter
  193. //so it is safe to do this check at top of loop.
  194. if (Char.IsDigit(parms[i][0]))
  195. break;
  196. if (htc.HttpCustomHeaders == null)
  197. htc.HttpCustomHeaders = new List<string>();
  198. htc.HttpCustomHeaders.Add(parms[i]);
  199. htc.HttpCustomHeaders.Add(parms[i+1]);
  200. i += 2;
  201. }
  202. break;
  203. case (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE:
  204. htc.HttpPragmaNoCache = (int.Parse(parms[i + 1]) != 0);
  205. break;
  206. }
  207. }
  208. }
  209. htc.RequestModule = this;
  210. htc.LocalID = localID;
  211. htc.ItemID = itemID;
  212. htc.Url = url;
  213. htc.ReqID = reqID;
  214. htc.HttpTimeout = httpTimeout;
  215. htc.OutboundBody = body;
  216. htc.ResponseHeaders = headers;
  217. htc.proxyurl = m_proxyurl;
  218. htc.proxyexcepts = m_proxyexcepts;
  219. // Same number as default HttpWebRequest.MaximumAutomaticRedirections
  220. htc.MaxRedirects = 50;
  221. if (StartHttpRequest(htc))
  222. {
  223. status = HttpInitialRequestStatus.OK;
  224. return htc.ReqID;
  225. }
  226. else
  227. {
  228. status = HttpInitialRequestStatus.DISALLOWED_BY_FILTER;
  229. return UUID.Zero;
  230. }
  231. }
  232. /// <summary>
  233. /// Would a caller to this module be allowed to make a request to the given URL?
  234. /// </summary>
  235. /// <returns></returns>
  236. public bool CheckAllowed(Uri url)
  237. {
  238. return m_outboundUrlFilter.CheckAllowed(url);
  239. }
  240. public bool StartHttpRequest(HttpRequestClass req)
  241. {
  242. if (!CheckAllowed(new Uri(req.Url)))
  243. return false;
  244. lock (HttpListLock)
  245. {
  246. m_pendingRequests.Add(req.ReqID, req);
  247. }
  248. req.Process();
  249. return true;
  250. }
  251. public void StopHttpRequest(uint m_localID, UUID m_itemID)
  252. {
  253. if (m_pendingRequests != null)
  254. {
  255. lock (HttpListLock)
  256. {
  257. HttpRequestClass tmpReq;
  258. if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq))
  259. {
  260. tmpReq.Stop();
  261. m_pendingRequests.Remove(m_itemID);
  262. }
  263. }
  264. }
  265. }
  266. /*
  267. * TODO
  268. * Not sure how important ordering is is here - the next first
  269. * one completed in the list is returned, based soley on its list
  270. * position, not the order in which the request was started or
  271. * finished. I thought about setting up a queue for this, but
  272. * it will need some refactoring and this works 'enough' right now
  273. */
  274. public IServiceRequest GetNextCompletedRequest()
  275. {
  276. lock (HttpListLock)
  277. {
  278. foreach (UUID luid in m_pendingRequests.Keys)
  279. {
  280. HttpRequestClass tmpReq;
  281. if (m_pendingRequests.TryGetValue(luid, out tmpReq))
  282. {
  283. if (tmpReq.Finished)
  284. {
  285. return tmpReq;
  286. }
  287. }
  288. }
  289. }
  290. return null;
  291. }
  292. public void RemoveCompletedRequest(UUID id)
  293. {
  294. lock (HttpListLock)
  295. {
  296. HttpRequestClass tmpReq;
  297. if (m_pendingRequests.TryGetValue(id, out tmpReq))
  298. {
  299. tmpReq.Stop();
  300. tmpReq = null;
  301. m_pendingRequests.Remove(id);
  302. }
  303. }
  304. }
  305. #endregion
  306. #region ISharedRegionModule Members
  307. public void Initialise(IConfigSource config)
  308. {
  309. m_proxyurl = config.Configs["Startup"].GetString("HttpProxy");
  310. m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions");
  311. m_outboundUrlFilter = new OutboundUrlFilter("Script HTTP request module", config);
  312. int maxThreads = 15;
  313. IConfig httpConfig = config.Configs["HttpRequestModule"];
  314. if (httpConfig != null)
  315. {
  316. maxThreads = httpConfig.GetInt("MaxPoolThreads", maxThreads);
  317. }
  318. m_pendingRequests = new Dictionary<UUID, HttpRequestClass>();
  319. // First instance sets this up for all sims
  320. if (ThreadPool == null)
  321. {
  322. STPStartInfo startInfo = new STPStartInfo();
  323. startInfo.IdleTimeout = 20000;
  324. startInfo.MaxWorkerThreads = maxThreads;
  325. startInfo.MinWorkerThreads = 1;
  326. startInfo.ThreadPriority = ThreadPriority.BelowNormal;
  327. startInfo.StartSuspended = true;
  328. startInfo.ThreadPoolName = "ScriptsHttpReq";
  329. ThreadPool = new SmartThreadPool(startInfo);
  330. ThreadPool.Start();
  331. }
  332. }
  333. public void AddRegion(Scene scene)
  334. {
  335. m_scene = scene;
  336. m_scene.RegisterModuleInterface<IHttpRequestModule>(this);
  337. }
  338. public void RemoveRegion(Scene scene)
  339. {
  340. scene.UnregisterModuleInterface<IHttpRequestModule>(this);
  341. if (scene == m_scene)
  342. m_scene = null;
  343. }
  344. public void PostInitialise()
  345. {
  346. }
  347. public void RegionLoaded(Scene scene)
  348. {
  349. }
  350. public void Close()
  351. {
  352. }
  353. public string Name
  354. {
  355. get { return m_name; }
  356. }
  357. public Type ReplaceableInterface
  358. {
  359. get { return null; }
  360. }
  361. #endregion
  362. }
  363. public class HttpRequestClass : IServiceRequest
  364. {
  365. // Constants for parameters
  366. // public const int HTTP_BODY_MAXLENGTH = 2;
  367. // public const int HTTP_METHOD = 0;
  368. // public const int HTTP_MIMETYPE = 1;
  369. // public const int HTTP_VERIFY_CERT = 3;
  370. // public const int HTTP_VERBOSE_THROTTLE = 4;
  371. // public const int HTTP_CUSTOM_HEADER = 5;
  372. // public const int HTTP_PRAGMA_NO_CACHE = 6;
  373. /// <summary>
  374. /// Module that made this request.
  375. /// </summary>
  376. public HttpRequestModule RequestModule { get; set; }
  377. private bool _finished;
  378. public bool Finished
  379. {
  380. get { return _finished; }
  381. }
  382. // public int HttpBodyMaxLen = 2048; // not implemented
  383. // Parameter members and default values
  384. public string HttpMethod = "GET";
  385. public string HttpMIMEType = "text/plain;charset=utf-8";
  386. public int HttpTimeout;
  387. public bool HttpVerifyCert = true;
  388. public IWorkItemResult WorkItem = null;
  389. //public bool HttpVerboseThrottle = true; // not implemented
  390. public List<string> HttpCustomHeaders = null;
  391. public bool HttpPragmaNoCache = true;
  392. // Request info
  393. private UUID _itemID;
  394. public UUID ItemID
  395. {
  396. get { return _itemID; }
  397. set { _itemID = value; }
  398. }
  399. private uint _localID;
  400. public uint LocalID
  401. {
  402. get { return _localID; }
  403. set { _localID = value; }
  404. }
  405. public DateTime Next;
  406. public string proxyurl;
  407. public string proxyexcepts;
  408. /// <summary>
  409. /// Number of HTTP redirects that this request has been through.
  410. /// </summary>
  411. public int Redirects { get; private set; }
  412. /// <summary>
  413. /// Maximum number of HTTP redirects allowed for this request.
  414. /// </summary>
  415. public int MaxRedirects { get; set; }
  416. public string OutboundBody;
  417. private UUID _reqID;
  418. public UUID ReqID
  419. {
  420. get { return _reqID; }
  421. set { _reqID = value; }
  422. }
  423. public HttpWebRequest Request;
  424. public string ResponseBody;
  425. public List<string> ResponseMetadata;
  426. public Dictionary<string, string> ResponseHeaders;
  427. public int Status;
  428. public string Url;
  429. public void Process()
  430. {
  431. _finished = false;
  432. lock (HttpRequestModule.ThreadPool)
  433. WorkItem = HttpRequestModule.ThreadPool.QueueWorkItem(new WorkItemCallback(StpSendWrapper), null);
  434. }
  435. private object StpSendWrapper(object o)
  436. {
  437. SendRequest();
  438. return null;
  439. }
  440. /*
  441. * TODO: More work on the response codes. Right now
  442. * returning 200 for success or 499 for exception
  443. */
  444. public void SendRequest()
  445. {
  446. HttpWebResponse response = null;
  447. Stream resStream = null;
  448. StringBuilder sb = new StringBuilder();
  449. byte[] buf = new byte[8192];
  450. string tempString = null;
  451. int count = 0;
  452. try
  453. {
  454. Request = (HttpWebRequest)WebRequest.Create(Url);
  455. Request.AllowAutoRedirect = false;
  456. //This works around some buggy HTTP Servers like Lighttpd
  457. Request.ServicePoint.Expect100Continue = false;
  458. Request.Method = HttpMethod;
  459. Request.ContentType = HttpMIMEType;
  460. if (!HttpVerifyCert)
  461. {
  462. // We could hijack Connection Group Name to identify
  463. // a desired security exception. But at the moment we'll use a dummy header instead.
  464. Request.Headers.Add("NoVerifyCert", "true");
  465. }
  466. // else
  467. // {
  468. // Request.ConnectionGroupName="Verify";
  469. // }
  470. if (!HttpPragmaNoCache)
  471. {
  472. Request.Headers.Add("Pragma", "no-cache");
  473. }
  474. if (HttpCustomHeaders != null)
  475. {
  476. for (int i = 0; i < HttpCustomHeaders.Count; i += 2)
  477. Request.Headers.Add(HttpCustomHeaders[i],
  478. HttpCustomHeaders[i+1]);
  479. }
  480. if (!string.IsNullOrEmpty(proxyurl))
  481. {
  482. if (!string.IsNullOrEmpty(proxyexcepts))
  483. {
  484. string[] elist = proxyexcepts.Split(';');
  485. Request.Proxy = new WebProxy(proxyurl, true, elist);
  486. }
  487. else
  488. {
  489. Request.Proxy = new WebProxy(proxyurl, true);
  490. }
  491. }
  492. foreach (KeyValuePair<string, string> entry in ResponseHeaders)
  493. if (entry.Key.ToLower().Equals("user-agent"))
  494. Request.UserAgent = entry.Value;
  495. else
  496. Request.Headers[entry.Key] = entry.Value;
  497. // Encode outbound data
  498. if (!string.IsNullOrEmpty(OutboundBody))
  499. {
  500. byte[] data = Util.UTF8.GetBytes(OutboundBody);
  501. Request.ContentLength = data.Length;
  502. using (Stream bstream = Request.GetRequestStream())
  503. bstream.Write(data, 0, data.Length);
  504. }
  505. Request.Timeout = HttpTimeout;
  506. try
  507. {
  508. // execute the request
  509. response = (HttpWebResponse) Request.GetResponse();
  510. }
  511. catch (WebException e)
  512. {
  513. if (e.Status != WebExceptionStatus.ProtocolError)
  514. {
  515. throw;
  516. }
  517. response = (HttpWebResponse)e.Response;
  518. }
  519. Status = (int)response.StatusCode;
  520. resStream = response.GetResponseStream();
  521. do
  522. {
  523. // fill the buffer with data
  524. count = resStream.Read(buf, 0, buf.Length);
  525. // make sure we read some data
  526. if (count != 0)
  527. {
  528. // translate from bytes to ASCII text
  529. tempString = Util.UTF8.GetString(buf, 0, count);
  530. // continue building the string
  531. sb.Append(tempString);
  532. if (sb.Length > 2048)
  533. break;
  534. }
  535. } while (count > 0); // any more data to read?
  536. ResponseBody = sb.ToString().Replace("\r", "");
  537. }
  538. catch (WebException e)
  539. {
  540. if (e.Status == WebExceptionStatus.ProtocolError)
  541. {
  542. HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response;
  543. Status = (int)webRsp.StatusCode;
  544. try
  545. {
  546. using (Stream responseStream = webRsp.GetResponseStream())
  547. {
  548. using (StreamReader reader = new StreamReader(responseStream))
  549. ResponseBody = reader.ReadToEnd();
  550. }
  551. }
  552. catch
  553. {
  554. ResponseBody = webRsp.StatusDescription;
  555. }
  556. }
  557. else
  558. {
  559. Status = (int)OSHttpStatusCode.ClientErrorJoker;
  560. ResponseBody = e.Message;
  561. }
  562. if (ResponseBody == null)
  563. ResponseBody = String.Empty;
  564. _finished = true;
  565. return;
  566. }
  567. catch (Exception e)
  568. {
  569. // Don't crash on anything else
  570. }
  571. finally
  572. {
  573. if (resStream != null)
  574. resStream.Close();
  575. if (response != null)
  576. response.Close();
  577. // We need to resubmit
  578. if (
  579. (Status == (int)HttpStatusCode.MovedPermanently
  580. || Status == (int)HttpStatusCode.Found
  581. || Status == (int)HttpStatusCode.SeeOther
  582. || Status == (int)HttpStatusCode.TemporaryRedirect))
  583. {
  584. if (Redirects >= MaxRedirects)
  585. {
  586. Status = (int)OSHttpStatusCode.ClientErrorJoker;
  587. ResponseBody = "Number of redirects exceeded max redirects";
  588. _finished = true;
  589. }
  590. else
  591. {
  592. string location = response.Headers["Location"];
  593. if (location == null)
  594. {
  595. Status = (int)OSHttpStatusCode.ClientErrorJoker;
  596. ResponseBody = "HTTP redirect code but no location header";
  597. _finished = true;
  598. }
  599. else if (!RequestModule.CheckAllowed(new Uri(location)))
  600. {
  601. Status = (int)OSHttpStatusCode.ClientErrorJoker;
  602. ResponseBody = "URL from HTTP redirect blocked: " + location;
  603. _finished = true;
  604. }
  605. else
  606. {
  607. Status = 0;
  608. Url = response.Headers["Location"];
  609. Redirects++;
  610. ResponseBody = null;
  611. // m_log.DebugFormat("Redirecting to [{0}]", Url);
  612. Process();
  613. }
  614. }
  615. }
  616. else
  617. {
  618. _finished = true;
  619. }
  620. }
  621. if (ResponseBody == null)
  622. ResponseBody = String.Empty;
  623. _finished = true;
  624. }
  625. public void Stop()
  626. {
  627. try
  628. {
  629. if (!WorkItem.Cancel())
  630. {
  631. WorkItem.Cancel(true);
  632. }
  633. }
  634. catch (Exception)
  635. {
  636. }
  637. }
  638. }
  639. }