private IAsyncResult GetResponse (string method, Uri uri, bool sendHeaders)
{
if ((uri.Scheme != "http") && (uri.Scheme != "https")) {
async_result.Exception = new SecurityException ("Bad scheme");
async_result.SetComplete ();
return async_result;
}
// this is a same site (site of origin, SOO) request; or
// we either already know the policy (previously downloaded); or
// we try to download the policy
if (!IsDownloadingPolicy ()) {
policy = CrossDomainPolicyManager.GetCachedWebPolicy (uri);
if (policy == null) {
// we'll download the policy *then* proceed to the requested URI
policy = CrossDomainPolicyManager.PolicyDownloadPolicy;
Uri silverlight_policy_uri = CrossDomainPolicyManager.GetSilverlightPolicyUri (uri);
BrowserHttpWebRequestInternal preq = new BrowserHttpWebRequestInternal (null, silverlight_policy_uri);
return preq.BeginGetResponse (new AsyncCallback (SilverlightPolicyCallback), preq);
}
}
// Console.WriteLine ("{0} '{1}' using policy: {2}", method, uri, policy);
HttpWebRequest wreq = GetHttpWebRequest (uri);
wreq.Method = method;
// store exception, to throw later, if we have no policy or are not allowed by the policy
if ((policy == null) || !policy.IsAllowed (wreq)) {
if ((policy == null) || (policy.Exception == null))
async_result.Exception = new SecurityException ();
else
async_result.Exception = policy.Exception;
async_result.SetComplete ();
return async_result;
}
// new in SL4 - unlike others it can be set (earlier) and is not checked later (CheckProtocolViolation)
// but still throws a SecurityException here
if (Headers.ContainsKey ("Proxy-Authorization"))
throw new SecurityException ();
if (!sendHeaders)
wreq.Headers.Clear ();
wreq.progress = progress;
return wreq.BeginGetResponse (new AsyncCallback (EndCallback), wreq);
}