/// <summary>Handle an authentication failure and possibly return a new response.</summary>
/// <remarks>Handle an authentication failure and possibly return a new response.</remarks>
/// <param name="conn">the connection that failed.</param>
/// <returns>new authentication method to try.</returns>
internal static HttpAuthMethod ScanResponse(HttpURLConnection conn)
{
string hdr = conn.GetHeaderField(HttpSupport.HDR_WWW_AUTHENTICATE);
if (hdr == null || hdr.Length == 0)
{
return NONE;
}
int sp = hdr.IndexOf(' ');
if (sp < 0)
{
return NONE;
}
string type = Sharpen.Runtime.Substring(hdr, 0, sp);
if (Sharpen.Runtime.EqualsIgnoreCase(HttpAuthMethod.Basic.NAME, type))
{
return new HttpAuthMethod.Basic();
}
else
{
if (Sharpen.Runtime.EqualsIgnoreCase(HttpAuthMethod.Digest.NAME, type))
{
return new HttpAuthMethod.Digest(Sharpen.Runtime.Substring(hdr, sp + 1));
}
else
{
return NONE;
}
}
}