diff options
author | Diva Canto | 2014-05-23 16:19:43 -0700 |
---|---|---|
committer | Diva Canto | 2014-05-23 16:19:43 -0700 |
commit | 20f20895cf1444071d5edc42e11a1fb94b1b1079 (patch) | |
tree | 0c7547590a89eec47886e0a8646f86ebbf449e63 /OpenSim/Framework/Communications | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC_OLD-20f20895cf1444071d5edc42e11a1fb94b1b1079.zip opensim-SC_OLD-20f20895cf1444071d5edc42e11a1fb94b1b1079.tar.gz opensim-SC_OLD-20f20895cf1444071d5edc42e11a1fb94b1b1079.tar.bz2 opensim-SC_OLD-20f20895cf1444071d5edc42e11a1fb94b1b1079.tar.xz |
Adds optional HTTP Basic Authentication to Robust service connectors.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Communications/RestClient.cs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/OpenSim/Framework/Communications/RestClient.cs b/OpenSim/Framework/Communications/RestClient.cs index e7f0ca8..89e6aa1 100644 --- a/OpenSim/Framework/Communications/RestClient.cs +++ b/OpenSim/Framework/Communications/RestClient.cs | |||
@@ -35,6 +35,8 @@ using System.Threading; | |||
35 | using System.Web; | 35 | using System.Web; |
36 | using log4net; | 36 | using log4net; |
37 | 37 | ||
38 | using OpenSim.Framework.ServiceAuth; | ||
39 | |||
38 | namespace OpenSim.Framework.Communications | 40 | namespace OpenSim.Framework.Communications |
39 | { | 41 | { |
40 | /// <summary> | 42 | /// <summary> |
@@ -297,7 +299,7 @@ namespace OpenSim.Framework.Communications | |||
297 | /// <summary> | 299 | /// <summary> |
298 | /// Perform a synchronous request | 300 | /// Perform a synchronous request |
299 | /// </summary> | 301 | /// </summary> |
300 | public Stream Request() | 302 | public Stream Request(IServiceAuth auth) |
301 | { | 303 | { |
302 | lock (_lock) | 304 | lock (_lock) |
303 | { | 305 | { |
@@ -307,6 +309,8 @@ namespace OpenSim.Framework.Communications | |||
307 | _request.Timeout = 200000; | 309 | _request.Timeout = 200000; |
308 | _request.Method = RequestMethod; | 310 | _request.Method = RequestMethod; |
309 | _asyncException = null; | 311 | _asyncException = null; |
312 | if (auth != null) | ||
313 | auth.AddAuthorization(_request.Headers); | ||
310 | 314 | ||
311 | // IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); | 315 | // IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); |
312 | try | 316 | try |
@@ -358,7 +362,7 @@ namespace OpenSim.Framework.Communications | |||
358 | } | 362 | } |
359 | } | 363 | } |
360 | 364 | ||
361 | public Stream Request(Stream src) | 365 | public Stream Request(Stream src, IServiceAuth auth) |
362 | { | 366 | { |
363 | _request = (HttpWebRequest) WebRequest.Create(buildUri()); | 367 | _request = (HttpWebRequest) WebRequest.Create(buildUri()); |
364 | _request.KeepAlive = false; | 368 | _request.KeepAlive = false; |
@@ -367,6 +371,8 @@ namespace OpenSim.Framework.Communications | |||
367 | _request.Method = RequestMethod; | 371 | _request.Method = RequestMethod; |
368 | _asyncException = null; | 372 | _asyncException = null; |
369 | _request.ContentLength = src.Length; | 373 | _request.ContentLength = src.Length; |
374 | if (auth != null) | ||
375 | auth.AddAuthorization(_request.Headers); | ||
370 | 376 | ||
371 | m_log.InfoFormat("[REST]: Request Length {0}", _request.ContentLength); | 377 | m_log.InfoFormat("[REST]: Request Length {0}", _request.ContentLength); |
372 | m_log.InfoFormat("[REST]: Sending Web Request {0}", buildUri()); | 378 | m_log.InfoFormat("[REST]: Sending Web Request {0}", buildUri()); |
@@ -384,7 +390,22 @@ namespace OpenSim.Framework.Communications | |||
384 | length = src.Read(buf, 0, 1024); | 390 | length = src.Read(buf, 0, 1024); |
385 | } | 391 | } |
386 | 392 | ||
387 | _response = (HttpWebResponse) _request.GetResponse(); | 393 | try |
394 | { | ||
395 | _response = (HttpWebResponse)_request.GetResponse(); | ||
396 | } | ||
397 | catch (WebException e) | ||
398 | { | ||
399 | m_log.WarnFormat("[REST]: Request {0} {1} failed with status {2} and message {3}", | ||
400 | RequestMethod, _request.RequestUri, e.Status, e.Message); | ||
401 | } | ||
402 | catch (Exception e) | ||
403 | { | ||
404 | m_log.WarnFormat( | ||
405 | "[REST]: Request {0} {1} failed with exception {2} {3}", | ||
406 | RequestMethod, _request.RequestUri, e.Message, e.StackTrace); | ||
407 | } | ||
408 | |||
388 | 409 | ||
389 | // IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); | 410 | // IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); |
390 | 411 | ||
@@ -423,7 +444,7 @@ namespace OpenSim.Framework.Communications | |||
423 | try | 444 | try |
424 | { | 445 | { |
425 | // Perform the operation; if sucessful set the result | 446 | // Perform the operation; if sucessful set the result |
426 | Stream s = Request(); | 447 | Stream s = Request(null); |
427 | ar.SetAsCompleted(s, false); | 448 | ar.SetAsCompleted(s, false); |
428 | } | 449 | } |
429 | catch (Exception e) | 450 | catch (Exception e) |