private IEnumerator DoRequest(WWW www, CancellationToken cancellationToken, bool verifyResponse, Action<Dictionary<string, object>> responseCallback)
{
using (www)
{
var monitor = new WWWConnectionMonitor(www);
while (!www.isDone && !cancellationToken.IsCanceled)
{
monitor.AssertLiveliness();
yield return null;
}
if (cancellationToken.IsCanceled)
{
yield break;
}
if (!string.IsNullOrEmpty(www.error))
{
throw new WwwErrorException(www);
}
PSDebug.Log("Request returned: {0}, text: {1}", www.url, www.text);
var response = ResponseAsDictionary(www);
if (verifyResponse)
{
var password = JSONDict.Wrap(response).Get<string>("meta", "password");
var responseDigest = ResponseDigest(www.text, password);
var sigHeader = www.responseHeaders.Get(X_SIGNATURE.ToUpper());
if (sigHeader != responseDigest)
{
throw new Exception(
string.Format("Singature mismatch in {0}. {1} vs {2}", www.url, sigHeader, responseDigest));
}
}
if (www.responseHeaders.ContainsKey("SET-COOKIE"))
{
SetCookie(www.responseHeaders["SET-COOKIE"]);
}
responseCallback(response);
}
}