Skip to content

Commit

Permalink
Load by default as Html when content type is null or empty
Browse files Browse the repository at this point in the history
Load by default as Html when content type is null or empty
  • Loading branch information
zzzprojects committed May 22, 2017
1 parent 3fcf79a commit 6584a09
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/HtmlAgilityPack/HtmlWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,7 @@ private HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc
_responseUri = resp.ResponseUri;

bool html = IsHtmlContent(resp.ContentType);
bool isUnknown = string.IsNullOrEmpty(resp.ContentType);

Encoding respenc = !string.IsNullOrEmpty(resp.ContentEncoding)
? Encoding.GetEncoding(resp.ContentEncoding)
Expand Down Expand Up @@ -1576,6 +1577,26 @@ private HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc
doc.Load(s, respenc);
}
}

if (doc != null && isUnknown)
{
try
{
if (respenc == null)
{
doc.Load(s, true);
}
else
{
doc.Load(s, respenc);
}
}
catch
{
// That’s fine, the content type was unknown so probably not HTML
// Perhaps trying to figure if the content contains some HTML before would be a better idea.
}
}
}
resp.Close();
}
Expand Down

0 comments on commit 6584a09

Please sign in to comment.